将字符转换为数据帧中的时间戳 [英] Converting character to timestamp in dataframe

查看:58
本文介绍了将字符转换为数据帧中的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个数据帧中有一个时间戳记,该时间戳记被认为是字符类。出于某种原因,我无法将其转换为poxis时间戳。

I have a timestamp in a dataframe that is recognized as a character class. For some reason, I am not able to convert it to a poxis timestamp.

这里是数据示例。

ID    dateTime    stage
1    2016-11-01T00:00:00.000Z  4.82
2    2016-11-01T00:15:00.000Z  4.83
3    2016-11-01T00:30:00.000Z  4.84
4    2016-11-01T00:45:00.000Z  4.85
5    2016-11-01T01:00:00.000Z  4.86
6    2016-11-01T01:15:00.000Z  4.87

我尝试使用以下内容。

format(df$dateTime, "Y%-%m-%d %h:%m")


as.Date(df$dateTime, "Y%-%m-%d %h:%m")



as.POSIXct(df$dateTime, tz="GMT")

以上尝试均无效。

有什么建议吗?

推荐答案

我们可以随时使用

library(anytime)
anytime('2016-11-01T00:15:00.000Z')
#[1] "2016-11-01 00:15:00 IST"

或使用 strptime

strptime('2016-11-01T00:15:00.000Z', '%Y-%m-%dT%H:%M:%OSZ')
#[1] "2016-11-01 00:15:00 IST"

这篇关于将字符转换为数据帧中的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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