Question

I am puzzled with this result:

a = "2008-03-03 12:30:38"

#I convert to POSIXct and set the timezone
dt = as.POSIXct(a, format="%Y-%m-%d %H:%M:%S", tz='Europe/Paris')

dt
[1] "2008-03-03 12:30:38 CET"

unclass(dt)
[1] 1204543838
attr(,"tzone")
[1] "Europe/Paris"

#I want to come back to POSIXct    
as.POSIXct(unclass(dt), origin='1970-01-01', tz='Europe/Paris')
[1] "2008-03-03 11:30:38 CET"

I would have expected to get back the date-time a, what is wrong here ?

Was it helpful?

Solution

As it says in ?as.POSIXct, the origin is in tz="GMT".

You can use .POSIXct instead:

.POSIXct(unclass(dt), tz='Europe/Paris')
# [1] "2008-03-03 12:30:38 CET"

OTHER TIPS

You may want to check the attribute: isdst To see if there is some Daylight Savings conversion going on in there somewhere. This page from the R manual on Date-Time Classes may be useful

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top