[英]How to convert time stamp string “2014-07-20T05:11:49.988Z” into POSIXt in R?
How to convert time stamp string “2014-07-20T05:11:49.988Z” into POSIXt in R? 如何在R中将时间戳字符串“ 2014-07-20T05:11:49.988Z”转换为POSIXt?
I want to know why the second is represented in 3 decimel places? 我想知道为什么第二个代表3个分位数? also what is the meaning of appending the 'Z' at the end of time stamp? 在时间戳的末尾附加“ Z”又是什么意思? Can anybody know how this string can be converted into time in R 任何人都可以知道如何将字符串转换为R中的时间
The "Z" is shorthand for UTC . “ Z”是UTC的简写 。 You can parse this in base R with 您可以使用
x <- as.POSIXct("2014-07-20T05:11:49.998Z",
format="%Y-%m-%dT%H:%M:%OSZ", tz="GMT")
Note that you generally either use POSIXct or POSIXlt rather than POSIXt directly (both have POSIXt as a base class) 请注意,通常您通常使用POSIXct或POSIXlt而不是直接使用POSIXt(两者都将POSIXt作为基类)
The lubridate
package has very robust parsers that I tend to prefer over manual specification of the format
in base R lubridate
软件包具有非常强大的解析器,我倾向于在基数R中首选手动format
该format
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
(t <- ymd_hms("2014-07-20T05:11:49.998Z"))
#> [1] "2014-07-20 05:11:49 UTC"
Created on 2019-03-11 by the reprex package (v0.2.1) 由reprex软件包 (v0.2.1)创建于2019-03-11
Making sure that the milliseconds that aren't printed aren't lost either: 确保未打印的毫秒数也不会丢失:
second(t)
#> [1] 49.998
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.