我如何从strptime中提取年份?

max*_*oku 1 datetime r

我有这种格式的时间:

t <- "4/2/2004 12:45"

I can extract day and month using these two lines:

strptime(t, "%m/%d/%Y %H:%M", tz="UTC")$day
strptime(t, "%m/%d/%Y %H:%M", tz="UTC")$mday
Run Code Online (Sandbox Code Playgroud)

但这并没有给我我想要的岁月.我给了我没有世纪的一年:

strptime(t, "%m/%d/%Y %H:%M", tz="UTC")$year
Run Code Online (Sandbox Code Playgroud)

我怎样才能准确地获得这一年?像1987年,2012年等.而不是87和12.

如果有任何其他功能可用于此,我也可以.

Jos*_*ich 6

添加1900.有关详细信息,请参阅详细信息部分?POSIXlt.

> tm <- "4/2/2004 12:45"
> strptime(tm, "%m/%d/%Y %H:%M", tz="UTC")$year
[1] 104
> strptime(tm, "%m/%d/%Y %H:%M", tz="UTC")$year + 1900
[1] 2004
Run Code Online (Sandbox Code Playgroud)