Reputation: 14370
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 ?
Upvotes: 1
Views: 80
Reputation: 176688
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"
Upvotes: 2
Reputation: 326
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
Upvotes: 0