< prev index next >

src/java.base/share/classes/java/time/Clock.java

Print this page

        

*** 153,163 **** * It is equivalent to {@code system(ZoneOffset.UTC)}. * * @return a clock that uses the best available system clock in the UTC zone, not null */ public static Clock systemUTC() { ! return new SystemClock(ZoneOffset.UTC); } /** * Obtains a clock that returns the current instant using the best available * system clock, converting to date and time using the default time-zone. --- 153,163 ---- * It is equivalent to {@code system(ZoneOffset.UTC)}. * * @return a clock that uses the best available system clock in the UTC zone, not null */ public static Clock systemUTC() { ! return SystemClock.UTC; } /** * Obtains a clock that returns the current instant using the best available * system clock, converting to date and time using the default time-zone.
*** 196,205 **** --- 196,208 ---- * @param zone the time-zone to use to convert the instant to date-time, not null * @return a clock that uses the best available system clock in the specified zone, not null */ public static Clock system(ZoneId zone) { Objects.requireNonNull(zone, "zone"); + if (zone == ZoneOffset.UTC) { + return SystemClock.UTC; + } return new SystemClock(zone); } //------------------------------------------------------------------------- /**
*** 449,458 **** --- 452,463 ---- */ static final class SystemClock extends Clock implements Serializable { private static final long serialVersionUID = 6740630888130243051L; private static final long OFFSET_SEED = System.currentTimeMillis()/1000 - 1024; // initial offest + static final SystemClock UTC = new SystemClock(ZoneOffset.UTC); + private final ZoneId zone; // We don't actually need a volatile here. // We don't care if offset is set or read concurrently by multiple // threads - we just need a value which is 'recent enough' - in other // words something that has been updated at least once in the last
< prev index next >