Skip to content

Instantly share code, notes, and snippets.

@plvhx
Created July 27, 2021 06:07
Show Gist options
  • Save plvhx/34039f3e1e1b065d40f15d65a0baaf3e to your computer and use it in GitHub Desktop.
Save plvhx/34039f3e1e1b065d40f15d65a0baaf3e to your computer and use it in GitHub Desktop.
converting rfc3339 to timestamp and back, like a boss.
-module(main).
-export([start/0]).
to_rfc3339(DateTime) ->
{{Y, M, D}, {H, I, S}} = DateTime,
io_lib:format(
"~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0BZ",
[Y, M, D, H, I, S]
).
to_rfc3339_serialize(DateTime) ->
lists:flatten(to_rfc3339(DateTime)).
start() ->
Tz = to_rfc3339_serialize(
calendar:local_time()
),
SysTime = calendar:rfc3339_to_system_time(
Tz,
[{unit, nanosecond}]
),
io:fwrite(
"RFC 3339 to system time: ~p~n",
[SysTime]
).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment