用lubridate解析日期时间 [英] Parse datetime with lubridate

查看:51
本文介绍了用lubridate解析日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下格式解析以下日期时间:

I am trying to parse the following datetime with the following format:

library(lubridate)
a <- "2004-05-07 18:24:58.666424"

我尝试了以下操作,但返回了NA

I tried the following, but returned NAs

b <- lubridate::mdy_hms(a)
c <- lubridate::mdy(a)

任何人都可以解释一下如何解析它.如果不使用lubridate,我也很好.

Could anyone please explain how to parse this. I am also fine if lubridate is not used.

推荐答案

使用lubridate,您可以指定秒使用特殊的S!OS格式的小数.有关更多解析选项,请参见?parse_date_time.

With lubridate, you can specify that your seconds have a decimal with the special S! or OS formats; see ?parse_date_time for more parsing options.

> parse_date_time("2004-05-07 18:24:58.666424", 'ymd HMS!')
[1] "2004-05-07 18:24:58 UTC"

或者,它似乎可以使用通常的默认"ymd HMS"进行解析:

Alternately, it seems to parse fine with just the usual default "ymd HMS":

parse_date_time("2004-05-07 18:24:58.666424", 'ymd HMS')

或速记

ymd_hms("2004-05-07 18:24:58.666424")

这篇关于用lubridate解析日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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