简体   繁体   中英

Convert date format to CCYYMMDD HH:MM:SS

How one goes about to reformat date to CCYYMMDD HH:MM:SS TZ ? (the TZ is optional)

Here is related post but I would need the solution within R.

Here are my dates, which I would need to reformat.

library(lubridate)

startdate <- as.Date("2015-01-01")

week.dates <- seq(startdate, by="1 week", length.out=12)
dat.week <- week.dates[wday(week.dates) != 1 & wday(week.dates) != 7]
biz.week <- format(as.POSIXct(as.Date(dat.week)), tz="America/Los_Angeles",usetz=TRUE)

EDIT: Specifically, needed format is: 'YYYYMMDD{SPACE}hh:mm:ss[{SPACE}TMZ]'

Just try:

strftime(dat.week,format="%Y%m%d %H:%M %Z")

You can also use format or as.character instead of strftime .

我想你也要求秒,所以这里有一个小的修改:

strftime(dat.week,format="%C%y%m%d %H:%M:%S %Z")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM