当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Elixir DateTime.to_gregorian_seconds用法及代码示例


Elixir语言中 DateTime.to_gregorian_seconds 相关用法介绍如下。

用法:

to_gregorian_seconds(datetime)
(从 1.11.0 开始)
@spec to_gregorian_seconds(Calendar.datetime()) :: {integer(), non_neg_integer()}

DateTime 结构转换为公历秒数和微秒数。

例子

iex> dt = %DateTime{year: 0000, month: 1, day: 1, zone_abbr: "UTC",
...>                hour: 0, minute: 0, second: 1, microsecond: {0, 0},
...>                utc_offset: 0, std_offset: 0, time_zone: "Etc/UTC"}
iex> DateTime.to_gregorian_seconds(dt)
{1, 0}

iex> dt = %DateTime{year: 2020, month: 5, day: 1, zone_abbr: "UTC",
...>                hour: 0, minute: 26, second: 31, microsecond: {5000, 0},
...>                utc_offset: 0, std_offset: 0, time_zone: "Etc/UTC"}
iex> DateTime.to_gregorian_seconds(dt)
{63_755_511_991, 5000}

iex> dt = %DateTime{year: 2020, month: 5, day: 1, zone_abbr: "CET",
...>                hour: 1, minute: 26, second: 31, microsecond: {5000, 0},
...>                utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"}
iex> DateTime.to_gregorian_seconds(dt)
{63_755_511_991, 5000}

相关用法


注:本文由纯净天空筛选整理自elixir-lang.org大神的英文原创作品 DateTime.to_gregorian_seconds(datetime)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。