`
somefuture
  • 浏览: 1078581 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

java8中的时间处理4 - Instant

 
阅读更多

 

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);
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics