View Source ExKits.Utils.Time (ex_kits v0.2.7)

时间相关工具

Summary

Functions

@spec china_now() :: {:ok, DateTime.t()}
@spec china_today() :: Date.t()
Link to this function

date_to_datetime(date, tz \\ "Asia/Shanghai")

View Source
@spec date_to_datetime(Date.t(), binary()) :: DateTime.t()
Link to this function

datetime_to_naive(datetime)

View Source
@spec datetime_to_naive(DateTime.t()) :: NaiveDateTime.t()
Link to this function

datetime_to_str(datetime, format \\ "%Y-%m-%d %H:%M:%S")

View Source
@spec datetime_to_str(DateTime.t(), String.t()) :: String.t()
Link to this function

datetime_to_ts(datetime)

View Source
@spec datetime_to_ts(DateTime.t()) :: integer()
Link to this function

naive_now(typ \\ :second)

View Source
@spec naive_now(atom()) :: NaiveDateTime.t()
Link to this function

naive_to_datetime(ndt, tz \\ "Asia/Shanghai")

View Source
@spec naive_to_datetime(NaiveDateTime.t(), Calendar.time_zone()) ::
  {:ok, DateTime.t()}
Link to this function

naive_to_datetime!(ndt, tz \\ "Asia/Shanghai")

View Source
@spec naive_to_datetime!(NaiveDateTime.t(), Calendar.time_zone()) :: DateTime.t()
@spec now(Calendar.time_zone()) :: {:ok, DateTime.t()}
@spec now!(Calendar.time_zone()) :: DateTime.t()
Link to this function

str_to_datetime(s, shift \\ "+08:00")

View Source
@spec str_to_datetime(String.t(), String.t()) :: {:ok, DateTime.t()}
Link to this function

timestamp(typ \\ :seconds)

View Source
@spec timestamp(atom()) :: integer()

get current timestamp

Example

iex> Common.TimeTool.timestamp(:seconds) 1534466694 iex> Common.TimeTool.timestamp(:milli_seconds) 1534466732335 iex> Common.TimeTool.timestamp(:micro_seconds) 1534466750683862 iex> Common.TimeTool.timestamp(:nano_seconds) 1534466778949821000

Link to this function

ts_to_datetime(ts, tz \\ "Asia/Shanghai")

View Source
@spec ts_to_datetime(integer(), Calendar.time_zone()) :: {:ok, DateTime.t()}