试图理解日期时间字符串中的“PT1H”

Trying to understand “PT1H” in a date-time string

我正在使用天气 API 将天气信息作为我项目的一项服务来下载。我试图了解一些我似乎无法找到相关信息的时区偏移量。

我使用的URL是:

https://api.weather.gov/gridpoints/VEF/154,48

这是一些示例 return 值:

"temperature": {
    "sourceUnit": "F",
    "uom": "unit:degC",
    "values": [
        {
            "validTime": "2019-05-11T16:00:00+00:00/PT1H",
            "value": 18.333333333333371
        },
        {
            "validTime": "2019-05-12T04:00:00+00:00/PT2H",
            "value": 16.1111111111112
        },
        {
            "validTime": "2019-05-12T21:00:00+00:00/PT4H",
            "value": 26.666666666666742
        },
        ...
    ]
}

我了解 PT 表示太平洋时区。但我似乎找不到任何关于 1H2H 等字符旁边的信息

如果有人能提供建议,我们将不胜感激 - 谢谢

PT1H = 一小时

I understand the PT means Pacific Timezone.

不,假设不正确。不是时区。

PT1H代表duration, a span of time not tied to the timeline. This format is defined in the ISO 8601标准。

P 标记开始,我想是“Period”的缩写,是持续时间的同义词。 T 将任何 years-months-days 部分与任何 hours-minutes-seconds 部分分开。

所以PT1H表示“一小时”。两个半小时为 PT2H30M.

正在解析

您输入的 "2019-05-11T16:00:00+00:00/PT1H" 结合了开始时刻和持续时间是 part of the ISO 8601 标准。

这样的组合字符串可以被Interval.parse method found in the ThreeTen-Extra库解析。

Interval interval = Interval.parse( "2019-05-11T16:00:00+00:00/PT1H" ) ;

一个Interval表示一对矩,按定义是一对Instant objects. In your case here, the second moment is calculated, by adding the duration to the starting moment. We can interrogate for the pair of moments, represented as Instant objects (always in UTC

Instant start = interval.getStart() ;
Instant stop = interval.getEnd() ;