【问题标题】:Timezone Raw Offsets时区原始偏移量
【发布时间】:2011-12-11 00:09:47
【问题描述】:

在对时区进行一些研究时,我发现了这个interesting post on the GeoNames forum

rawOffset gives the fixed timezone.
dstOffset gives the civil time offset from GMT on July 1st
gmtOffset gives the civil time offset from GMT on January 1st

在南半球,例如智利 (http://ws.geonames.org/timezone?lat=-33.46912&lng=-70.641997) 我们有 以下值:

rawOffset = -4 indicating the timezone
dstOffset = -4
gmtOffset = -3, which means that daylight saving time is in use in January.

在北半球,例如荷兰 (http://ws.geonames.org/timezone?lat=51.589322&lng=4.774491):

rawOffset = 1
dstOffset = 2
gmtOffset = 1, indacting that daylight saving time is in use in July.

rawOffset 也不是第一次看到了,this SO answer(Java 中)也依赖它。

我的目标是使用原始偏移量来构建一个时区下拉菜单,显示每组城市的 UTC 偏移量,现在 I'm listing all the transitions for the timezone 并使用非 DST 偏移量,但我上面提到的帖子表明南半球是错误的。


编辑: http://download.oracle.com/javase/1.4.2/docs/api/java/util/TimeZone.html#getRawOffset%28%29

GeoNames 的 Marc 告诉我,他们使用 Java 方法获得了原始偏移量。

任何 Java 向导都知道他们是如何做到的吗?或者在哪里可以浏览他们getRawOffset()的源代码?


关于如何在 PHP 中获取原始偏移量的任何想法?

【问题讨论】:

  • “原始偏移”还有其他名称吗?
  • 你需要处理什么?从其他问题根本不清楚。
  • 也不确定问题是什么,但也许php.net/manual/en/datetimezone.gettransitions.php 可以以某种方式为您提供所需的内容。
  • @Gordon:我已经在使用DateTimeZone::getTransitions(),但它只返回一个带有偏移量的字段和另一个布尔字段(isdst),我想我无法弄清楚原始从那里偏移。
  • @hakre:我不这么认为,我知道标准偏移量(也就是不使用 DST 时与 UTC 的偏移量)、DST 偏移量和原始偏移量......

标签: java php date time timezone


【解决方案1】:

不清楚为什么需要原始偏移量。

在 PHP 中,给定时间 + 位置,您可以实例化一个 DateTime 对象,然后调用其 getOffset() 方法来计算当前时区偏移量。遍历不同的位置,这应该是您获得下拉菜单所需的全部内容,不是吗?

http://www.php.net/manual/en/datetime.getoffset.php

【讨论】:

    猜你喜欢
    • 2012-01-01
    • 2014-04-15
    • 2011-09-02
    • 2011-12-13
    • 2021-09-20
    • 2011-08-04
    • 1970-01-01
    • 2019-03-14
    • 2020-11-07
    相关资源
    最近更新 更多