您的位置:首页 > 编程语言 > Java开发

Java经典实例:纪元秒和本地日期时间互换

2016-11-28 17:47 239 查看
Java版本:1.8开始

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

/**
* Created by Frank
*/
public class CurrentDatetime {
public static void main(String[] args) {
// 纪元秒和本地日期时间互换
Instant epochSec = Instant.ofEpochSecond(1000000000L);
ZoneId zId = ZoneId.systemDefault();
ZonedDateTime then = ZonedDateTime.ofInstant(epochSec, zId);
System.out.println("The epoch was a billion seconds old on " + then);
}
}


运行输出:

The epoch was a billion seconds old on 2001-09-09T09:46:40+08:00[Asia/Shanghai]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: