R:日期/时间"YYYY-MM-DDThh:mm:ss.sTZD";进口 [英] R: date/time "YYYY-MM-DDThh:mm:ss.sTZD" import

查看:64
本文介绍了R:日期/时间"YYYY-MM-DDThh:mm:ss.sTZD";进口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在R中导入以下日期/时间格式示例?我愿意将所有信息都保留在这种格式内.

How can I import the folowing date/time format example in R ? I'm willing to keep all information within this format.

2016-09-12T09:47:00.000+0200

其中:

 YYYY = four-digit year
 MM   = two-digit month (01=January, etc.)
 DD   = two-digit day of month (01 through 31)
 hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
 mm   = two digits of minute (00 through 59)
 ss   = two digits of second (00 through 59)
 s    = one or more digits representing a decimal fraction of a second
 TZD  = time zone designator (Z or +hh:mm or -hh:mm)

我尝试了 strptime 失败,因为我找不到如何匹配 s TZD 的示例,

I've tried strptime without success since I cannot find how to match s and TZD, example:

> strptime("2016-09-12T09:47:00.000+0200", format = '%Y-%m-%dT%H:%M:%S.000%z')
[1] "2016-09-12 09:47:00

推荐答案

要匹配小数秒(从docs?strptime中的文档中获取),请使用:

To match the decimal fraction of a second (from the docs ?strptime in Examples) use:

format = '%Y-%m-%dT%H:%M:%OS%z'

然后,查看3位数字:

op <- options(digits.secs = 3)
strptime("2016-09-12T09:47:00.123+0200", format = '%Y-%m-%dT%H:%M:%OS%z')
##[1] "2016-09-12 03:47:00.123"

要回到看不到3位数字的状态:

To go back to not seeing the 3-digits:

options(op)

我相信这确实可以解析UTC的偏移量(即 +0200 ).我在美国的东海岸,是美国东部时间(-0400).因此,我比(+0200)晚6个小时,因此 09:47:00.123 + 0200 变为 03:47:00.123 EDT.

I believe this does parse the offset from UTC (i.e., the +0200). I'm on the east coast of the United States, and it is EDT (-0400). Therefore, I'm 6 hours behind (+0200) so that 09:47:00.123+0200 becomes 03:47:00.123 EDT.

这篇关于R:日期/时间"YYYY-MM-DDThh:mm:ss.sTZD";进口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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