日期为两位数的年份 [英] as.Date with two-digit years

查看:88
本文介绍了日期为两位数的年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果出于某种原因我用as.Date(date, format="%d.%m.%y")转换了日期10.10.61(DD.MM.YY),它会将其转换为 2061 -10-10 .

If I convert the date 10.10.61 (DD.MM.YY) with as.Date(date, format="%d.%m.%y") for some reason it converts it into 2061-10-10.

是否有一种优雅的方法可以解决此问题,还是必须手动将其切成薄片并在前面加上"19"?

Is there an elegant way to correct for this or do I have to do it manually by slicing the string and adding "19" in front?

我还尝试了 zoo 软件包,该软件包会产生相同(错误)的结果.

I've also tried the zoo package which brings up the same (wrong) result.

推荐答案

x = format(as.Date("10.10.61", "%d.%m.%y"), "19%y-%m-%d")
x = as.Date(x)
x
class(x)

这篇关于日期为两位数的年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆