Java 8's Clock class
Java 8 adds a Clock class to obtain the current timestamp, or date and time information in the current time zone. Where System.currentTimeInMillis() and TimeZone.getDefault() were used before, they can be replaced by Clock.
package com.shxt.demo02; import java.time.Clock; public class Demo10 { public static void main(String[] args) { // Returns the current time based on your system clock and set to UTC. Clock clock = Clock.systemUTC(); System.out.println("Clock : " + clock.millis()); // Returns time based on system clock zone Clock defaultClock = Clock.systemDefaultZone(); System.out.println("Clock : " + defaultClock.millis()); } }
The above is the detailed content of How to use the Clock class in Java8. For more information, please follow other related articles on the PHP Chinese website!