本文介绍了为什么此Joda补偿无法正确设置夏令时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码使用Joda来计算任何给定日期的偏移量,例如

I have the following code using Joda to calculate offset for any given day, for example

int offset = DateTimeZone.forID("EST").getOffset(new DateTime(2013,8,1,1,1));

这将使我的补偿为-18000000。但对于:

this will give me offset of -18000000. But for:

 int offset = DateTimeZone.forID("EST").getOffset(new DateTime(2012,12,1,1,1));

这也为我提供了-18000000的补偿。

this also give me offset of -18000000.

好像没有将夏时制纳入计算。有人知道为什么吗?谢谢。

Looks like daylightsaving is not taken in to calculation. Anyone knows why? Thanks.

我正在使用Joda-time-2.3

I am using Joda-time-2.3

推荐答案

您是在明确告诉它忽略夏令时。

You are explicitly telling it to ignore Daylight Savings Time.

EST是东部标准时间,与EDT(夏令时)显着不同。

EST is Eastern Standard Time, notably different than EDT, which is Daylight Savings Time.

相反,请尝试使用ID US / Eastern,因此

Instead, try using the ID US/Eastern, so

DateTimeZone.forID("US/Eastern")

可以找到可用时区的完整列表。美国/东部是美国/纽约的别名

A complete list of the time zones available can be found here. US/Eastern is an alias for America/New_York

这篇关于为什么此Joda补偿无法正确设置夏令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 16:14