且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java8中的时间处理4 - Instant

更新时间:2022-06-01 23:29:34

 

Instant 类是机器易读的时间信息,存放的是unix时间戳。

import java.time.Duration;
import java.time.Instant;

public class InstantExample {

	public static void main(String[] args) {
		Instant timestamp = Instant.now();
		System.out.println("当前时间 = "+timestamp);
		
		Instant specificTime = Instant.ofEpochMilli(timestamp.toEpochMilli());
		System.out.println("特定时间 = "+specificTime);
		
		//时间段
		Duration thirtyDay = Duration.ofDays(30);
		System.out.println(thirtyDay);
	}
}