gpt4 book ai didi

timestamp - 如何转换Erlang :timestamp() to normal date format?

转载 作者:行者123 更新时间:2023-12-02 00:13:22 28 4
gpt4 key购买 nike

我想将 erlang:timestamp() 的结果转换为正常的日期类型,公历类型。

普通日期类型表示“日-月-年,时:分:秒”。

ExampleTime = erlang:timeStamp(),

ct:pal("~p", [ExampleTime]).

这显示 {1568,869478,181646}

我猜单位是秒,但不确定它代表什么。

如何用代码转换它及其概念。更具体的,我不知道,但举个例子,

{1568, 869478, 181646} == {年+月,日,小时+分钟}。

最佳答案

请查看文档erlang:timestamp() , 它说

erlang:timestamp() -> Timestamp

Types

Timestamp = timestamp()

timestamp() =

{MegaSecs :: integer() >= 0,

Secs :: integer() >= 0,

MicroSecs :: integer() >= 0}

Returns current Erlang system time on the format {MegaSecs, Secs, MicroSecs}...

然后stdlib库的module calendar提供了几个转换函数比如calendar:now_to_datetime(Now) :

1> calendar:now_to_datetime({1568,869478,181646}).
{{2019,9,19},{5,4,38}}

关于timestamp - 如何转换Erlang :timestamp() to normal date format?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58004415/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com