org.joda.time |日光节约时间(DST)和当地时区偏移 [英] org.joda.time | Day Light Saving time (DST) and local time zone offset

查看:121
本文介绍了org.joda.time |日光节约时间(DST)和当地时区偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是为了验证这一点:我有这种跛脚和脑死亡的方法来计算我当前位置的时区偏移量。我想知道当Day Light Saving时间问题时我是否需要调整它(目前我的位置有冬令时,CET时区,因此很难验证)。

just to verify this: I have this lame and brain dead method to calculate the time zone offset for my current location. I wonder if I need to adjust it when Day Light Saving time comes into question (currently we have Winter Time at my location, CET time zone, so it's hard to verify).

// The local time zone's offset
private  int getLocalOffset() {
    DateTimeZone defaultZone = DateTimeZone.getDefault();
    return defaultZone.getOffset(null) / 1000 / 60 / 60;
}

感谢任何提示。

推荐答案

通常情况下,Joda时间会自行处理DST,因此您不必担心。但是,我注意到你将 null 传递给getOffset()。鉴于时区偏移取决于日期,你真的应该通过你计算偏移的日期/时间,否则你会得到错误的结果。

Normally, Joda time will take care of DST by itself, so you don't have to worry about it. However, I notice that you are passing null to getOffset(). Given that the time zone offset depends on the date, you really should be passing the date/time at which you are calculating the offset, or you're going to get wrong results.

同样在我之前的评论中提到:请注意,某些时区的偏移量不是整数小时。例如印度格林威治标准时间+5:30

Also as mentionned in my previous comment: Be aware that some timezones have an offset that isn't a whole number of hours. India for example is at GMT +5:30

这篇关于org.joda.time |日光节约时间(DST)和当地时区偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆