erlang时间操作

erlang 时间函数操作
1.本地时间
  local_time() ->
    calendar:local_time().

2.UTC世界时间
  world_time() ->
    calendar:universal_time().

3.日期转换成秒数
  calendar:datetime_to_gregorian_seconds({{2019,4,3},{17,5,44}}).

4.两个日期大小对比
  calendar:datetime_to_gregorian_seconds({{2019,4,3},{17,5,44}}) - calendar:datetime_to_gregorian_seconds({{2019,5,3},{17,5,44}})

5.秒数转换成日期
  calendar:gregorian_seconds_to_datetime(63721530344).

6.获得时间戳的方法
 (1)%时间转时间戳,格式:{{2013,11,13}, {18,0,0}}
  DateTime = calendar:universal_time(). %%必须是UTC世界时间
  datetime_to_timestamp(DateTime) ->
    calendar:datetime_to_gregorian_seconds(DateTime) - calendar:datetime_to_gregorian_seconds({{1970,1,1}, {0,0,0}}).
 (2)%os:timestamp() 操作系统时间
  timestamp() ->
    {M, S, _} = os:timestamp(),
    M * 1000000 + S.
 (3)%erlang:now() erlang虚拟机时间
  timestamp() ->
  {M, S, _} = erlang:now(),
  M * 1000000 + S.

posted @ 2019-04-03 17:20  幸运使者  阅读(838)  评论(0编辑  收藏  举报