根据当地时区(TimeZone)计算时间查(LocalDateTime)

介绍一篇JAVA8 LocalDateTime的用法:

https://www.cnblogs.com/huanshilang/p/12013386.html

 

时区的获取:

TimeZone.getTimeZone("Hongkong")

 

 

 

复制代码

Date date1= new Date(long1); Date date2= new Date(long2);
//时区
TimeZone.getTimeZone("Hongkong");

LocalDateTime largeLocalDate = date1.toInstant().atZone(timeZone.toZoneId())
.toLocalDateTime();
LocalDateTime largeLocalDate1 =date2.toInstant().atZone(timeZone.toZoneId())
.toLocalDateTime();

Duration duration = Duration.between(largeLocalDate1, largeLocalDate);

//计算相差多少小天
long differDay  = duration.toDays();

//计算相差多少小时
long differHour = duration.toHours();

//相差的分钟数
long minutes = duration.toMinutes();


复制代码

 



posted @   泉水姐姐。  阅读(788)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
历史上的今天:
2020-02-28 常见Mysql优化
2020-02-28 JAVA8 函数式接口
点击右上角即可分享
微信分享提示