Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang converting timestamp to Year-Month-DayTHour:Min:SecZ format

Tags:

erlang

Hi I want to convert erlang:now(). timestamp output :

> erlang:now().
{1425,589373,955614}

into Year-Month-DayTHour:Min:SecZ format. Whats the fastes way to do it?

like image 513
Kamrul Khan Avatar asked Dec 07 '25 02:12

Kamrul Khan


2 Answers

Not sure that this is fastest way, but I'd try this one:

{{Year, Month, Day}, {Hour, Minute, Second}} = calendar:now_to_datetime(erlang:now()),
StrTime = lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w",[Year,Month,Day,Hour,Minute,Second])).
like image 56
Viacheslav Kovalev Avatar answered Dec 09 '25 21:12

Viacheslav Kovalev


The format you're interested in is known as ISO 8601. If you're looking for more than a quick conversion, I've liked this library from Sean Sawyer: https://github.com/seansawyer/erlang_iso8601

like image 26
Nathaniel Waisbrot Avatar answered Dec 09 '25 19:12

Nathaniel Waisbrot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!