在R中查找lubridate包的年份日期

在R中查找lubridate包的年份日期,r,lubridate,R,Lubridate,我正在寻找使用lubridate的POSIXct类对象的日期。例如 使用lubridate很容易找到一周或一个月的哪一天: > lubridate::wday("2015-12-09 04:27:56 EST", labels = T) Wed > lubridate::day("2015-12-09 04:27:56 EST") 9 在一年中的某一天,有没有一种简单的方法可以做到这一点?我已经搜索了文档和其他问题,但还没有找到答案 正确的函数是yday,如中所示 lubridat

我正在寻找使用lubridate的POSIXct类对象的日期。例如

使用lubridate很容易找到一周或一个月的哪一天:

> lubridate::wday("2015-12-09 04:27:56 EST", labels = T)
Wed
> lubridate::day("2015-12-09 04:27:56 EST")
9

在一年中的某一天,有没有一种简单的方法可以做到这一点?我已经搜索了文档和其他问题,但还没有找到答案

正确的函数是
yday
,如中所示

lubridate::yday(Sys.time())

在你/杰西无意中回答这个问题之前,我想出了一个更复杂的方法:

# compute the time interval from the first of the year until now
YTD = interval(floor_date(now(), unit='year'), now())
# compute the length of the interval in days, and discard the fractional part
as.integer(time_length(YTD, "day"))
顺便说一下,u/blindjesse的答案更简洁的版本是:

lubridate::yday(now())

不需要润滑油:
格式(Sys.time(),“%j”)