Weird as.POSIXct behavior depending on daylight savings time

佐手、 提交于 2019-12-11 05:07:15

问题


It seems there is a bug in as.POSIXct. Or what is going on?

as.POSIXct("27/03/2006 02:05:38", format="%d/%m/%Y %H:%M:%S") 
[1] "2006-03-27 02:05:38 CEST"

as.POSIXct("26/03/2006 02:05:38", format="%d/%m/%Y %H:%M:%S")
[1] NA

March 26, 2006 happened as far as I know...


回答1:


if you really want it printed with the times you can always do.

as.POSIXct("26/03/2006 02:05:38", format="%d/%m/%Y %H:%M:%S", tz = "UTC")
#[1] "2006-03-26 02:05:38 UTC"

Just make sure you do this for all conversions for consistency.

As Wikipedia states:

UTC does not change with a change of seasons, but local time or civil time may change if a time zone jurisdiction observes daylight saving time (summer time). For example, local time on the east coast of the United States is five hours behind UTC during winter, but four hours behind while daylight saving is observed there.



来源:https://stackoverflow.com/questions/50116692/weird-as-posixct-behavior-depending-on-daylight-savings-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!