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?
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])).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With