你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
使用时区规范将本地日期/时间转换为 UTC 日期/时间。
语法
datetime_local_to_utc(
from,
)
timezone
详细了解语法约定。
参数
客户 | 类型 | 必需 | 说明 |
---|---|---|---|
起始 | datetime |
✔️ | 要转换的本地日期/时间。 |
timezone | string |
✔️ | 所需日期/时间的时区。 该值必须是受支持的时区之一。 |
返回
返回一个 UTC 日期/ 时间,该 日期时间 对应于指定的 timezone
本地日期时间。
例子
以下示例演示如何将本地日期/时间转换为 UTC 日期/时间。
datatable(local_dt: datetime, tz: string)
[ datetime(2020-02-02 20:02:20), 'US/Pacific',
datetime(2020-02-02 20:02:20), 'America/Chicago',
datetime(2020-02-02 20:02:20), 'Europe/Paris']
| extend utc_dt = datetime_local_to_utc(local_dt, tz)
输出
local_dt | tz | utc_dt |
---|---|---|
2020-02-02 20:02:20.0000000 | 欧洲/巴黎 | 2020-02-02 19:02:20.0000000 |
2020-02-02 20:02:20.0000000 | 美洲/芝加哥 | 2020-02-03 02:02:20.0000000 |
2020-02-02 20:02:20.0000000 | 美国/太平洋 | 2020-02-03 04:02:20.0000000 |
注意
通常,UTC 和本地时间之间存在 1:1 映射,但是在 DST 转换附近存在时间不明确性。 如果时钟由于 DST 而提前,则从本地转换为 UTC 然后再转换回本地可能会在两个本地日期/时间值之间产生小时偏移量。
range Local from datetime(2022-03-27 01:00:00.0000000) to datetime(2022-03-27 04:00:00.0000000) step 1h
| extend UTC=datetime_local_to_utc(Local, 'Europe/Brussels')
| extend BackToLocal=datetime_utc_to_local(UTC, 'Europe/Brussels')
| extend diff=Local-BackToLocal
本地 | UTC(协调世界时) | BackToLocal | 差异 |
---|---|---|---|
2022-03-27 02:00:00.0000000 | 2022-03-27 00:00:00.0000000 | 2022-03-27 01:00:00.0000000 | 01:00:00 |
2022-03-27 01:00:00.0000000 | 2022-03-27 00:00:00.0000000 | 2022-03-27 01:00:00.0000000 | 00:00:00 |
2022-03-27 03:00:00.0000000 | 2022-03-27 01:00:00.0000000 | 2022-03-27 03:00:00.0000000 | 00:00:00 |
2022-03-27 04:00:00.0000000 | 2022-03-27 02:00:00.0000000 | 2022-03-27 04:00:00.0000000 | 00:00:00 |
相关内容
- 若要从 UTC 转换为本地时间,请参阅 datetime_utc_to_local()
- 时区
- 支持的时区列表
- format_datetime()