當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。