【发布时间】:2016-11-19 18:23:18
【问题描述】:
我在这里犯了一个小错误,但无法弄清楚问题所在。
我需要获取随机日期的一周中的星期一的日期.. 似乎我得到了完全不同的东西
mydate <- date("2013-11-05")
format(mydate, "%A") # this is Tuesday, right
#[1] "Tuesday"
month(mydate) # Month November, right
#[1] 11
myyr <- year(mydate); myyr # year is 2013, right
#[1] 2013
day(mydate) # day number is 5, right
#[1] 5
mywk <- isoweek(mydate);mywk # weeknumber is 45, right (yes, not US convention here)
#[1] 45
format(mydate, "%V") # weeknumber is 45, right as well
#[1] "45"
# Monday of week 45 is 2013-11-04 but strptime following gives something else...
strptime(paste0(myyr, "Monday", mywk), "%Y%A%V")
#[1] "2013-11-19 EET"
# and for checking
strptime("2013Monday45","%Y%A%V")
#[1] "2013-11-19 EET"
提前致谢
【问题讨论】:
-
目前尚不清楚您想要给定日期的确切日期,但也许这会有所帮助:
d <- as.Date("2013-11-05"); d - as.numeric(format(d, "%w")) + 1 -
看到
%V根据?strpitime是Accepted but ignored on input。请改用%W。
标签: r iso8601 strptime date-conversion week-number