如果已知 UTC 的日期和该时区的时间,如何知道该时区的日期?
How to know date at a timezone if date at UTC in known and time at that timezone is known?
例如:
- 我知道 UTC 日期是 2020-05-15
- 我知道时间在
Pacific/Auckland (+12) 是 8:00
如何使用这些已知数据计算 Pacific/Auckland (+12) 中的日期?
我会采用 "try the obvious date/time combination, and see whether it works" 的简单方法:
- 在给定时区使用 "UTC date" 和当地时间尝试
DateTime
。在这种情况下,您最终会在 Pacific/Auckland 中得到 2020-05-15T08:00:00
- 将
DateTime
转换为 UTC,在本例中以 2020-05-14T20:00:00Z 结尾
- 检查结果日期:
- 是不是太早了?将我们的候选人提前一天。
- 来不及了吗?将我们的候选人后退一天。
- 对吗?太好了 - 我们的候选人已经正确了。
例如:
- 我知道 UTC 日期是 2020-05-15
- 我知道时间在 Pacific/Auckland (+12) 是 8:00
如何使用这些已知数据计算 Pacific/Auckland (+12) 中的日期?
我会采用 "try the obvious date/time combination, and see whether it works" 的简单方法:
- 在给定时区使用 "UTC date" 和当地时间尝试
DateTime
。在这种情况下,您最终会在 Pacific/Auckland 中得到 2020-05-15T08:00:00
- 将
DateTime
转换为 UTC,在本例中以 2020-05-14T20:00:00Z 结尾
- 检查结果日期:
- 是不是太早了?将我们的候选人提前一天。
- 来不及了吗?将我们的候选人后退一天。
- 对吗?太好了 - 我们的候选人已经正确了。