在erlang中将时间戳转换为日期时间

use*_*569 23 erlang time date

如何将时间戳(1970年1月1日以来的毫秒数...)转换为Erlang中的Date或DateTime格式?像{年,月,日}这样的东西.

ton*_*nys 20

大致:

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.
Run Code Online (Sandbox Code Playgroud)


Jer*_*all 8

事实上,我有一个github gist,其中包含一堆日期时间实用程序,用于此目的:http://gist.github.com/104903.日历中包含大部分低级管道.