根据当地时区(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();


 




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM