Java实现纪元秒和本地日期时间互换的方法【经典实例】
本文实例讲述了Java实现纪元秒和本地日期时间互换的方法。分享给大家供大家参考,具体如下:
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] */ } }
eclipse运行结果如下:
PS:这里再为大家推荐几款时间及日期相关工具供大家参考使用:
在线日期/天数计算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi
在线日期计算器/相差天数计算器:
http://tools.jb51.net/jisuanqi/datecalc
在线日期天数差计算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq
Unix时间戳(timestamp)转换工具:
http://tools.jb51.net/code/unixtime
希望本文所述对大家java程序设计有所帮助。
相关文章
解决SpringBoot项目中log4j与logback的Jar包冲突问题
这篇文章主要给大家介绍了解决SpringBoot项目中log4j与logback的Jar包冲突问题,文中有详细的解决方法和冲突的原因,有遇到相同问题的朋友可以参考阅读本文2023-10-10springboot2.5.6集成RabbitMq实现Topic主题模式(推荐)
这篇文章主要介绍了springboot2.5.6集成RabbitMq实现Topic主题模式(推荐),pom.xml引入依赖和常量类创建,本文通过实例代码给大家介绍的非常详细,需要的朋友参考下吧2021-11-11
最新评论