如何提取时间戳记日期有R中的月份名称
问题描述:
我需要从一个时间戳格式中提取日期,例如如何提取时间戳记日期有R中的月份名称
“八月-02-2017上午7点54分31秒UTC”
我想提取日期形式2017-08-02。如何在R中做到这一点?我尝试使用“lubridate”包,但它无法解析它。
答
尝试随时随地库
library(anytime)
anydate("Aug-02-2017 07:54:31 AM UTC")
[1] "2017-08-02"
答
使用基本as.POSIXct
功能:
> format(as.POSIXct("Aug-02-2017 07:54:31 AM UTC",format='%b-%d-%Y'))
[1] "2017-08-02"
答
> s1="Aug-02-2017 07:54:31 AM UTC"
> library(lubridate)
Attaching package: ‘lubridate’
The following object is masked from ‘package:base’:
date
> d1=mdy_hms(s1)
> d1
[1] "2017-08-02 07:54:31 UTC"
> date(d1)
[1] "2017-08-02"