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)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。