我有以下字符selectedMonths <- c("201501")
如何获得两个字符串
"2015-01-01 00:00:00"
和
"2015-01-31 23:59:59"
答案 0 :(得分:1)
尝试
library(zoo)
paste(as.Date(as.yearmon(selectedMonths, format = '%Y%m')), "00:00:00")
paste(as.Date(as.yearmon(selectedMonths, format = '%Y%m'), frac = 1), "23:59:59")
给出了:
#[1] "2015-01-01 00:00:00"
#[1] "2015-01-31 23:59:59"