[erlang-questions] NTP timestamp
Håkan Stenholm
hokan.stenholm@REDACTED
Fri Dec 28 01:02:04 CET 2007
József Bérces wrote:
> Hi,
>
> I would like to convert NTP timestamps (seconds elapsed since 00:00:00 January 1st, 1900) to Erlang date/time tuples (UTC). I did not find any such functions in the OTP libraries. It seems that there is no function for converting now() to UTC date and time, either.
>
> Any help would be welcome.
>
something like this should work, to convert
NTP timestamps (in UTC) to {date(), time()} in UTC:
%% returns: {date(), time()}
NTPtimestamps_to_datetime(NTPSeconds) ->
%% 1900:01:01 00:00:00 in gregorian seconds
NTPBase = calendar:datetime_to_gregorian_seconds({1900,1,1}, {0,0,0}),
GregorianSec = NTPBase + NTPSeconds,
calendar:gregorian_seconds_to_datetime(Seconds).
the calendar module has the following functions for converting now() to
UTC {date(), time()}:
now_to_universal_time(Now) -> {Date, Time}
now_to_datetime(Now) -> {Date, Time}
> Thanks,
> Jozsef
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list