How can I convert a timestamp (number of milliseconds since 1 Jan 1970...) to Date or DateTime format in Erlang? Something like {Year,Month,Day}.
A:
Roughly:
msToDate(Milliseconds) ->
BaseDate = calendar:datetime_to_gregorian_seconds({{1970,1,1},{0,0,0}}),
Seconds = BaseDate + (Milliseconds div 1000),
{ Date,_Time} = calendar:gregorian_seconds_to_datetime(Seconds),
Date.
tonys
2009-05-05 15:28:16
+1
A:
It just so happens that I have a github gist with a bunch of datetime utilities for exactly this purpose: http://gist.github.com/104903. Calendar has most of the low level plumbing for this stuff.
Jeremy Wall
2009-05-08 03:20:54