gpt4 book ai didi

r - 在 R 中从 UTC 转换为日期格式

转载 作者:行者123 更新时间:2023-12-02 05:43:39 24 4
gpt4 key购买 nike

我有一个 UTC 时间戳。我想在 R 中将它转换成 YYYY/MM/DD 格式。

例如,1318394558766。我尝试 format 命令失败。

感谢任何帮助。

谢谢!

最佳答案

您可以使用as.POSIXctas.POSIXlt。但是,您必须知道您的毫秒数开始的起始日期。

as.POSIXct(1318394558766/1000, origin='1970-01-01')

> unlist(as.POSIXlt(1318394558766/1000, origin='1970-01-01'))
sec min hour mday mon year wday yday isdst
38.766 42.000 21.000 11.000 9.000 111.000 2.000 283.000 1.000
>

然后你可以使用format来得到想要的YYYY/MM/DD:

format(as.POSIXct(1318394558766/1000, origin='1970-01-01'), format='%Y/%m/%d')

关于r - 在 R 中从 UTC 转换为日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11233960/

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