smallex v0.1.8 Dt

DateTime utiity.

Link to this section Summary

Link to this section Functions

Link to this function add_days(dt, days)
Link to this function cut_second(str, cut_second \\ :cut_second)
Link to this function diff_ymd_string(to, from, units)
Link to this function from_string(dt_str, format_str, with_status \\ :no_status)

Datetime from string

Examples

iex> Dt.from_string( "2018/01/02 23:44:09", "%Y/%m/%d %H:%M:%S" )
~N[2018-01-02 23:44:09]
iex> Dt.from_string( "2018/01/02 23:44:09", "%Y/%m/%d %H:%M:%S", :with_status )
{ :ok, ~N[2018-01-02 23:44:09] }
Link to this function hyphen_to_slash(str)

Hyphen to slash

Examples

iex> Dt.hyphen_to_slash( "2018-01-02 03:04:05" )
"2018/01/02 03:04:05"
iex> Dt.hyphen_to_slash( "2018/01/02 03:04:05" )
"2018/01/02 03:04:05"
Link to this function list_ymd(to, from)
Link to this function slash_to_hyphen(str)

Slash to hyphen

Examples

iex> Dt.slash_to_hyphen( "2018/01/02 03:04:05" )
"2018-01-02 03:04:05"
iex> Dt.slash_to_hyphen( "2018-01-02 03:04:05" )
"2018-01-02 03:04:05"
Link to this function to_datetime(str)

Get datetime from string/tuple

Examples

iex> Dt.to_datetime( "2018/1" )
~N[2018-01-01 00:00:00]
iex> Dt.to_datetime( "2018/ 1" )
~N[2018-01-01 00:00:00]
iex> Dt.to_datetime( "2018/01" )
~N[2018-01-01 00:00:00]
iex> Dt.to_datetime( "2018/1/2" )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( "2018/1/2 3:4" )
~N[2018-01-02 03:04:00]
iex> Dt.to_datetime( "2018/1/2 3:4:5" )
~N[2018-01-02 03:04:05]
iex> Dt.to_datetime( "2018/1/2 03:04" )
~N[2018-01-02 03:04:00]
iex> Dt.to_datetime( "2018/1/2 03:04:05" )
~N[2018-01-02 03:04:05]
iex> Dt.to_datetime( "2018/ 1/ 2" )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( "2018/1/ 2" )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( "2018/01/ 2" )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( "2018/01/02" )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( "2018/01/02 23:44" )
~N[2018-01-02 23:44:00]
iex> Dt.to_datetime( "2018/01/02 23:44:09" )
~N[2018-01-02 23:44:09]
iex> Dt.to_datetime( "2018/01/02 23:44:09.005" )
~N[2018-01-02 23:44:09.005]
iex> Dt.to_datetime( "2018-01-02" )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( "2018-01-02 23:44" )
~N[2018-01-02 23:44:00]
iex> Dt.to_datetime( "2018-01-02 23:44:09" )
~N[2018-01-02 23:44:09]
iex> Dt.to_datetime( "2018-01-02 23:44:09.005" )
~N[2018-01-02 23:44:09.005]
iex> Dt.to_datetime( "Jan-02-2018" )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( "Jan-02-2018 23:44" )
~N[2018-01-02 23:44:00]
iex> Dt.to_datetime( "Jan-02-2018 23:44:09" )
~N[2018-01-02 23:44:09]
iex> Dt.to_datetime( "Jan-02-2018 23:44:09.005" )
~N[2018-01-02 23:44:09.005]
iex> Dt.to_datetime( "Jan-02-18" )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( "Jan-02-18 23:44" )
~N[2018-01-02 23:44:00]
iex> Dt.to_datetime( "Jan-02-18 23:44:09" )
~N[2018-01-02 23:44:09]
iex> Dt.to_datetime( "Jan-02-18 23:44:09.005" )
~N[2018-01-02 23:44:09.005]
#iex> Dt.to_datetime( "Jan-02-98" )
#~N[1998-01-02 00:00:00]
#iex> Dt.to_datetime( "Jan-02-98 23:44" )
#~N[1998-01-02 23:44:00]
#iex> Dt.to_datetime( "Jan-02-98 23:44:09" )
#~N[1998-01-02 23:44:09]
#iex> Dt.to_datetime( "Jan-02-98 23:44:09.005" )
#~N[1998-01-02 23:44:09.005]
iex> Dt.to_datetime( "January-02-2018" )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( "January-02-2018 23:44" )
~N[2018-01-02 23:44:00]
iex> Dt.to_datetime( "January-02-2018 23:44:09" )
~N[2018-01-02 23:44:09]
iex> Dt.to_datetime( "January-02-2018 23:44:09.005" )
~N[2018-01-02 23:44:09.005]
iex> Dt.to_datetime( "2018-01-02 23:44:09Z" )
~N[2018-01-02 23:44:09]
iex> Dt.to_datetime( "2018-01-02T23:44:09Z" )
~N[2018-01-02 23:44:09]
iex> Dt.to_datetime( { 2018, 1, 2 } )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( { { 2018, 1, 2 }, { 23, 44, 9 } } )
~N[2018-01-02 23:44:09]
iex> Dt.to_datetime( ~D[2018-01-02] )
~N[2018-01-02 00:00:00]
iex> Dt.to_datetime( ~N[2018-01-02 23:10:07] )
~N[2018-01-02 23:10:07]
Link to this function to_jst(utc, cut_second \\ :cut_second)

To JST string from UTC

Examples

iex> Dt.to_jst( "2018/1/2 10:23:45" )
"2018/01/02 19:23"
iex> Dt.to_jst( "2018/1/2 15:23:45" )
"2018/01/03 00:23"
Link to this function to_string(dt, format_str, with_status \\ :no_status)

Datetime to string

Examples

iex> Dt.to_string( ~N[2018-01-02 23:44:09.005], "%Y/%m/%d %H:%M:%S" )
"2018/01/02 23:44:09"
iex> Dt.to_string( ~N[2018-01-02 23:44:09.005], "%Y/%m/%d %H:%M:%S.%L" )
"2018/01/02 23:44:09.005"
iex> Dt.to_string( ~N[2018-01-02 23:44:09.005], "%Y/%m/%d %H:%M:%S", :with_status )
{ :ok, "2018/01/02 23:44:09" }
Link to this function to_ym_string(dt)

To yyyy/mm string

Examples

iex> Dt.to_ym_string( ~N[2018-01-02 03:04:05] )
"2018/01"
Link to this function to_ymd_string(dt)

To yyyy/mm/dd string

Examples

iex> Dt.to_ymd_string( ~N[2018-01-02 03:04:05] )
"2018/01/02"

To yyyy/mm/dd string

Examples

iex> Dt.to_ymd_string( ~N[2018-01-02 03:04:05] )
"2018/01/02"