简体   繁体   English

R中as.Date的代码说明

[英]Code explanation for as.Date in R

Consider this code: 考虑以下代码:

test_date<-"01-Jan-64"  
as.Date(test_date,"%d-%b-%y")
## [1] "2064-01-01"     
test_date<-"01-Jan-69"  
as.Date(test_date,"%d-%b-%y")  
## [1] "1969-01-01"

Why has 64 been read as 2064 and 69 as 1969? 为什么64被读为2064,而69被读为1969?

From ?strptime ?strptime

%y Year without century (00–99). %y无世纪的年份(00-99)。 On input, values 00 to 68 are prefixed by 20 and 69 to 99 by 19 – that is the behaviour specified by the 2004 and 2008 POSIX standards... 输入时,值00到68分别以20和69到99的19为前缀–这是2004和2008 POSIX标准指定的行为...

Basically don't use two digit years if there is any risk of ambiguity. 如果存在歧义的风险,基本上不要使用两位数的年份。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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