Home  >  Article  >  Java  >  How to use the Clock class in Java8

How to use the Clock class in Java8

PHPz
PHPzforward
2023-04-25 15:37:161574browse

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete