Created
July 27, 2021 06:07
-
-
Save plvhx/34039f3e1e1b065d40f15d65a0baaf3e to your computer and use it in GitHub Desktop.
converting rfc3339 to timestamp and back, like a boss.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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