简体   繁体   中英

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. 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). You need "%Y" .

R> strptime("2007-06-11T09:15:35Z", "%Y-%m-%dT%H:%M:%SZ")
[1] "2007-06-11 09:15:35 CDT"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM