我需要從一個時間戳格式中提取日期,例如如何提取時間戳記日期有R中的月份名稱
「八月-02-2017上午7點54分31秒UTC」
我想提取日期形式2017-08-02。如何在R中做到這一點?我嘗試使用「lubridate」包,但它無法解析它。
我需要從一個時間戳格式中提取日期,例如如何提取時間戳記日期有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"