【问题标题】:Day Light saving adjustment in Java [duplicate]Java中的夏令时调整[重复]
【发布时间】:2018-09-06 15:08:38
【问题描述】:
startDate.setTime(validationDate);
endDate.setTime(prevDutyEndDate);
noOfDays=Math.abs((Long)((startDate.getTimeInMillis() - endDate.getTimeInMillis())/(1000 * 60 * 60 * 24)));

在上面的代码中,sn-ps startDate 设置为 2018 年 3 月 7 日 00:00:00,endDate 设置为 3 月 14 日 00:00:00。在 3 月 11 日 CST 到期日光节约调整中,noOfDays 计算得出 6.95 而不是 7。如何通过代码处理 DST 调整并将值设为 7。

【问题讨论】:

  • 你能用java.time.LocalDate代替java.util.Calendar吗?这将是最好的起点,IMO...

标签: java dst


【解决方案1】:

四舍五入到最接近的整数

【讨论】:

  • 我不认为舍入到最接近的整数是处理夏令时的正确方法
猜你喜欢
  • 2011-08-01
  • 2015-07-14
  • 2011-11-05
  • 2012-02-18
  • 2015-08-15
  • 2011-11-20
  • 2016-09-18
  • 1970-01-01
相关资源
最近更新 更多