Elixir語言中 NaiveDateTime.from_iso8601
相關用法介紹如下。
用法:
from_iso8601(string, calendar \\ Calendar.ISO)
@spec from_iso8601(String.t(), Calendar.calendar()) :: {:ok, t()} | {:error, atom()}
解析 ISO 8601:2019 說明的擴展“日期和時間”格式。
時區偏移量可能包含在字符串中,但它們將被簡單地丟棄,因為此類信息不包含在原始日期時間中。
如標準中所述,如果需要,可以省略分隔符"T",因為此函數中沒有歧義。
注意內置 Calendar.ISO 不支持閏秒。
例子
iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07")
{:ok, ~N[2015-01-23 23:50:07]}
iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07")
{:ok, ~N[2015-01-23 23:50:07]}
iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07Z")
{:ok, ~N[2015-01-23 23:50:07]}
iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07.0")
{:ok, ~N[2015-01-23 23:50:07.0]}
iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07,0123456")
{:ok, ~N[2015-01-23 23:50:07.012345]}
iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07.0123456")
{:ok, ~N[2015-01-23 23:50:07.012345]}
iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123Z")
{:ok, ~N[2015-01-23 23:50:07.123]}
iex> NaiveDateTime.from_iso8601("2015-01-23P23:50:07")
{:error, :invalid_format}
iex> NaiveDateTime.from_iso8601("2015:01:23 23-50-07")
{:error, :invalid_format}
iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07A")
{:error, :invalid_format}
iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:61")
{:error, :invalid_time}
iex> NaiveDateTime.from_iso8601("2015-01-32 23:50:07")
{:error, :invalid_date}
iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123+02:30")
{:ok, ~N[2015-01-23 23:50:07.123]}
iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123+00:00")
{:ok, ~N[2015-01-23 23:50:07.123]}
iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123-02:30")
{:ok, ~N[2015-01-23 23:50:07.123]}
iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123-00:00")
{:error, :invalid_format}
iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123-00:60")
{:error, :invalid_format}
iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123-24:00")
{:error, :invalid_format}
相關用法
- Elixir NaiveDateTime.from_iso8601!用法及代碼示例
- Elixir NaiveDateTime.from_gregorian_seconds用法及代碼示例
- Elixir NaiveDateTime.from_erl!用法及代碼示例
- Elixir NaiveDateTime.from_erl用法及代碼示例
- Elixir NaiveDateTime.utc_now用法及代碼示例
- Elixir NaiveDateTime.truncate用法及代碼示例
- Elixir NaiveDateTime.convert!用法及代碼示例
- Elixir NaiveDateTime.new!用法及代碼示例
- Elixir NaiveDateTime.to_erl用法及代碼示例
- Elixir NaiveDateTime.diff用法及代碼示例
- Elixir NaiveDateTime.to_iso8601用法及代碼示例
- Elixir NaiveDateTime.local_now用法及代碼示例
- Elixir NaiveDateTime.compare用法及代碼示例
- Elixir NaiveDateTime.to_string用法及代碼示例
- Elixir NaiveDateTime.new用法及代碼示例
- Elixir NaiveDateTime.convert用法及代碼示例
- Elixir NaiveDateTime.to_time用法及代碼示例
- Elixir NaiveDateTime.to_date用法及代碼示例
- Elixir NaiveDateTime.to_gregorian_seconds用法及代碼示例
- Elixir NaiveDateTime.add用法及代碼示例
- Elixir NaiveDateTime用法及代碼示例
- Elixir Node.ping用法及代碼示例
- Elixir Node.start用法及代碼示例
- Elixir StringIO.flush用法及代碼示例
- Elixir Calendar.ISO.date_to_string用法及代碼示例
注:本文由純淨天空篩選整理自elixir-lang.org大神的英文原創作品 NaiveDateTime.from_iso8601(string, calendar \\ Calendar.ISO)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。