解析格式为YYYY-MM-DDTHH-MM-SSZ的ISO 8601日期时间 [英] Parse ISO 8601 date-time in format YYYY-MM-DDTHH-MM-SSZ

查看:585
本文介绍了解析格式为YYYY-MM-DDTHH-MM-SSZ的ISO 8601日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有如下时间戳的大型数据框:

I have a large dataframe with time stamps that look like this:

"2019-05-15T01:42:15.072Z"

它类似于 ISO 8601组合的日期和时间表示形式

如何将该字符串解析为真实的日期时间格式?

How can I parse this string into a real date-time format?

数据中的字符( T Z )似乎很难。

The characters (T and Z) inside the data seems to make it difficult.

推荐答案

只需在 as.POSIXct 中指定格式即可解析时间戳(或 strptime

You can simply parse the timestamp by specifying the format in as.POSIXct (or strptime)

as.POSIXct("2019-05-15T01:42:15.072Z", format = "%Y-%m-%dT%H:%M:%OSZ")
#[1] "2019-05-15 01:42:15 AEST"

说明:

%Y %m %d 表示年份(含世纪),月份和日期; %H %M %OS 表示小时,分钟和秒(包括毫秒)。 T Z 只需添加到 format 字符串中,因为

%Y, %m and %d denote the year (with century), month and day; %H, %M and %OS denote the hours, minutes and seconds (including milliseconds). The T and Z are simply added to the format string, because


格式字符串中不属于转换规范的任何字符均按字面意义进行解释

Any character in the format string not part of a conversion specification is interpreted literally

有关不同的转换规范,请参见?strptime

See ?strptime for the different conversion specifications.

这篇关于解析格式为YYYY-MM-DDTHH-MM-SSZ的ISO 8601日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆