识别ISO 8601中的时区 [英] Identifying time zones in ISO 8601

查看:111
本文介绍了识别ISO 8601中的时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不,我不是在说区域偏移量-区域偏移量在一年中可能会有所不同,例如DST.我说的是IANA维护的实际时区.我了解ISO 8601不支持这些 ,对吗?

No, I'm not talking about zone offsets --- those can vary during the year for a region based on e.g. DST. I'm talking about the actual time zones maintained by IANA. I understand these are not supported by ISO 8601, correct?

平台将如何支持识别类似ISO 8601的字符串表示形式中的时区?我注意到最新的Java日期/时间库为此使用了扩展的ISO 8601格式,例如 2011-12-03T10:15:30 + 01:00 [欧洲/巴黎] .(请参见 DateTimeFormatter API .)

What are platforms doing to support identifying time zones in ISO 8601-like string representations? I notice that the latest Java date/time library is using an extended ISO 8601 format for this, e.g. 2011-12-03T10:15:30+01:00[Europe/Paris]. (See DateTimeFormatter API.)

是否存在一些用于扩展ISO 8601以支持时区指定的融合约定(例如与其他语言和平台)?

Is there some converging convention (e.g. with other languages and platforms) for extending ISO 8601 to support time zone designation?

推荐答案

更新:

现在有一个IETF提案草案,用于使用方括号中的时区标识符来扩展RFC3339,其中包括: https://github.com/ryzokuken/draft-ryzokuken-datetime-extended

我了解ISO 8601不支持这些功能,对吗?

I understand these are not supported by ISO 8601, correct?

正确.ISO-8601本身与时区标识符无关.IANA/Olson TZ名称不是标准".它们只是我们拥有的最可靠的东西.(有些人可能会认为它们是事实标准.)

Correct. ISO-8601 does not concern itself with time zone identifiers. IANA/Olson TZ names are not a "standard". They are just the most reliable thing we have. (Some may consider them the de facto standard.)

平台正在为此提供支持吗?

What are platforms doing to support this?

到底支持什么?您的问题的这一部分尚不清楚.如果您打算支持IANA时区,那么到处都是.有些平台是内置的,有些平台则依赖库.如果要支持ISO-8601日期-时间偏移+时区ID的字符串表示形式,则某些平台具有此功能,而某些平台则没有.如果您想了解更多,就必须更加具体.

Support what exactly? This part of your question is unclear. If you mean to support IANA time zones, well that's all over the place. Some platforms have them built-in, and some rely on libraries. If you mean to support a string representation of an ISO-8601 date-time-offset + time zone ID, some platforms have this and some do not. You'll have to be more specific if you want to know more.

我注意到最新的Java日期/时间库为此使用了扩展的ISO 8601格式,例如2011-12-03T10:15:30 + 01:00 [欧洲/巴黎].(请参见DateTimeFormatter API.)

I notice that the latest Java date/time library is using an extended ISO 8601 format for this, e.g. 2011-12-03T10:15:30+01:00[Europe/Paris]. (See DateTimeFormatter API.)

我认为您是在谈论 DateTimeFormatter.ISO_ZONED_DATE_TIME .文档专门说:

I think you are talking about DateTimeFormatter.ISO_ZONED_DATE_TIME. The docs say specifically:

类似于ISO- 日期时间格式...

...扩展了ISO-8601扩展偏移日期时间格式,以添加时区.方括号中的部分不属于ISO-8601标准的一部分.

...extends the ISO-8601 extended offset date-time format to add the time-zone. The section in square brackets is not part of the ISO-8601 standard.

这是Java的特定格式,而不是标准.

So this is Java's specific format, not a standard.

是否存在一些用于扩展ISO 8601以支持时区指定的融合约定(例如与其他语言和平台)?

Is there some converging convention (e.g. with other languages and platforms) for extending ISO 8601 to support time zone designation?

据我所知,目前尚无将ISO8601时间戳和IANA时区标识符组合成单一格式的标准.一个人可以用许多不同的方式来表示它,包括:

As far as I know, there is currently no standard that covers the combining of an ISO8601 timestamp and an IANA time zone identifier into a single format. One could represent it many different ways, including:

  • 2011-12-03T10:15:30 + 01:00 [欧洲/巴黎] (这是Java 8中的默认设置)
  • 2011-12-03T10:15:30 + 01:00(欧洲/巴黎)
  • 2011-12-03T10:15:30 + 01:00欧洲/巴黎
  • 2011-12-03T10:15:30 + 01:00-欧洲/巴黎
  • 2011-12-03T10:15:30 + 01:00/欧洲/巴黎
  • 2011-12-03T10:15:30 + 01:00 |欧洲/巴黎
  • 2011-12-03T10:15:30欧洲/巴黎(+01)(这是Noda Time中的默认值)
  • 2011-12-03T10:15:30+01:00[Europe/Paris] (this is the default in Java 8)
  • 2011-12-03T10:15:30+01:00(Europe/Paris)
  • 2011-12-03T10:15:30+01:00 Europe/Paris
  • 2011-12-03T10:15:30+01:00 - Europe/Paris
  • 2011-12-03T10:15:30+01:00/Europe/Paris
  • 2011-12-03T10:15:30+01:00|Europe/Paris
  • 2011-12-03T10:15:30 Europe/Paris (+01) (this is the default in Noda Time)

如果您要查找的是一种以标准化方式在API中包含 ZonedDateTime 或类似数据的方法,我个人的建议是将时区名称传递到单独的字段中.这样,数据的每个部分都可以达到最佳状态.例如在JSON中:

If what you're looking for is a way to include a ZonedDateTime or similar data in an API in a standardized manner, my personal recommendation would be to pass the time zone name in a separate field. That way, each portion of data is as good as it can be. For example in JSON:

{
  "timestamp": "2011-12-03T10:15:30+01:00",
  "timezone": "Europe/Paris"
}

这篇关于识别ISO 8601中的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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