[英]In R, how to convert a character of specific format into a date?
I have a character string that deals with time: 我有一个处理时间的字符串:
"2007-06-11T09:15:35Z"
However, I cannot convert this into date using the following command: 但是,我无法使用以下命令将其转换为日期:
strptime("2007-06-11T09:15:35Z", paste("%y-%m-%d","T","%H:%M:%S","Z",sep=""))
I got the output as NA instead. 我得到的输出为NA。 What went wrong?
什么地方出了错? How should I correctly deal with date and time?
如何正确处理日期和时间?
Use the correct format. 使用正确的格式。
"%y"
is for 2-digit years (without the century). "%y"
表示两位数的年份(无世纪)。 You need "%Y"
. 您需要
"%Y"
。
R> strptime("2007-06-11T09:15:35Z", "%Y-%m-%dT%H:%M:%SZ")
[1] "2007-06-11 09:15:35 CDT"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.