80. Explaining the difference between Clock.systemUTC() and Clock.systemDefaultZone()
Let’s start with the following three lines of code:
System.out.println(Clock.systemDefaultZone());
System.out.println(system(ZoneId.systemDefault()));
System.out.println(Clock.systemUTC());
The output reveals that the first two lines are similar. Both of them display the default time zone (in my case, Europe/Bucharest):
SystemClock[Europe/Bucharest]
SystemClock[Europe/Bucharest]
The third line is different. Here, we see Z
time zone, which is specific to the UTC time zone and indicates the presence of a zone offset:
SystemClock[Z]
On the other hand, creating an Instant
reveals that Clock.systemUTC()
and Clock.systemDefaultZone()
produce the same result:
System.out.println(Clock.systemDefaultZone().instant());
System.out.println(system(ZoneId.systemDefault()).instant());
System.out.println(Clock.systemUTC().instant());
The instant time is the same in all three...