Home > Java > javaTutorial > body text

How to use the Clock class in Java8

PHPz
Release: 2023-04-25 15:37:16
forward
1626 people have browsed it

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());       
}  
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template