将字符串转换为日期,格式为:“ dd.mm.yyyy” [英] Convert string to date, format: "dd.mm.yyyy"

查看:116
本文介绍了将字符串转换为日期,格式为:“ dd.mm.yyyy”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

D <- "06.12.1948"                 # which is dd.mm.yyyy
as.Date(D, "%d.%m.%y")            # convert to date
[1] "2019-12-06"                  # ????    

我想念的是什么?

Sys.getlocale(category = LC_ALL)
[1] LC_COLLATE = German_Austria.1252; LC_CTYPE = German_Austria.1252; LC_MONETARY = German_Austria.1252; LC_NUMERIC = C; LC_TIME = German_Austria.1252

Sys.getlocale(category = "LC_ALL") [1] "LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;LC_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Austria.1252"


推荐答案

格式区分大小写(%y为believe昧且依赖系统,我相信):

The format is case-sensitive ("%y" is ambiguous and system dependent, I believe):

as.Date(D, "%d.%m.%Y")
[1] "1948-12-06"

帮助主题?strptime 具有详细信息:

The help topic ?strptime has details:

 ‘%y’ Year without century (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, but they do
      also say ‘it is expected that in a future version the default
      century inferred from a 2-digit year will change’.

这篇关于将字符串转换为日期,格式为:“ dd.mm.yyyy”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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