datetime_local_to_utc()

使用时区规范将本地日期/时间转换为 UTC 日期/时间。

语法

datetime_local_to_utc(from,)timezone

详细了解语法约定

参数

客户 类型​​ 必需 说明
from datetime 要转换的本地日期/时间。
timezone string 所需日期/时间的时区。 该值必须是受支持的时区之一。

返回

UTC 日期/时间,对应于指定 timezone 中的本地日期/时间

示例

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 Europe/Paris 2020-02-02 19:02:20.0000000
2020-02-02 20:02:20.0000000 America/Chicago 2020-02-03 02:02:20.0000000
2020-02-02 20:02:20.0000000 US/Pacific 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
Local UTC BackToLocal diff
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