gpt4 book ai didi

r - 18 位时间戳到常规日期格式

转载 作者:行者123 更新时间:2023-12-04 07:16:39 25 4
gpt4 key购买 nike

我有一个带有 18 位时间戳的数据集。
如何将它们转换为常规日期格式,例如“%Y-%m-%d %H:%M:%0S6”?
复制一个时间戳是:637201135513320448
我尝试使用 as.POSIXct()提到的功能 here ,但它返回 NA .我认为它不是为这么多数字而设计的。我在 c# here 上找到了一个提示,那里有人遇到了类似的问题。但我无法在 R 上解决这个问题。

最佳答案

如果这确实是 C# 类型的时间戳,您首先需要将其转换为 as.POSIXct 的正确值。上类:

timestamp <- 637201135513320448
epoch0.Csharp <- 621355968000000000 # value of Unix Time Origin in C# timestamp

timestamp.conv <- (timestamp - epoch0.Csharp) / 1e7 # C# has 10000 ticks per millisecond == 1e7 ticks per second which is the unit of the unix timestamp

dateTime <- as.POSIXct(timestamp.conv,origin="1970-01-01")

dateTime
[1] "2020-03-18 08:32:31 CET"

关于r - 18 位时间戳到常规日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68725715/

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