Skip to content
Prev 255937 / 398506 Next

Problem to convert date to number

On Apr 6, 2011, at 7:55 AM, Chris82 wrote:

            
Using the example from help(chron)

 > as.POSIXlt(x)
# chron times are assumed to be UTC but are printed with the current  
local value
[1] "1992-02-27 18:03:20 EST" "1992-02-27 17:29:56 EST"
[3] "1992-01-13 20:03:30 EST" "1992-02-28 13:21:03 EST"
[5] "1992-02-01 11:56:26 EST"
 > as.POSIXlt(x, tz="UTC")
[1] "1992-02-27 23:03:20 UTC" "1992-02-27 22:29:56 UTC"
[3] "1992-01-14 01:03:30 UTC" "1992-02-28 18:21:03 UTC"
[5] "1992-02-01 16:56:26 UTC"
 > as.POSIXlt(x, tz="CEST")  # "not working"
[1] "1992-02-27 23:03:20 UTC" "1992-02-27 22:29:56 UTC"
[3] "1992-01-14 01:03:30 UTC" "1992-02-28 18:21:03 UTC"
[5] "1992-02-01 16:56:26 UTC"

So it makes me wonder if as.POSIXct considers CEST to be a valid tz  
value.

 > as.POSIXlt(x, tz="XYZST")
[1] "1992-02-27 23:03:20 UTC" "1992-02-27 22:29:56 UTC"
[3] "1992-01-14 01:03:30 UTC" "1992-02-28 18:21:03 UTC"
[5] "1992-02-01 16:56:26 UTC"

 > as.POSIXlt(x, tz="EST5EDT")  # where  I am, and seems to be working
[1] "1992-02-27 18:03:20 EST" "1992-02-27 17:29:56 EST"
[3] "1992-01-13 20:03:30 EST" "1992-02-28 13:21:03 EST"
[5] "1992-02-01 11:56:26 EST"

But despite the returned code from Sys.time() that TLA  (EDT) does not  
"work":
 > Sys.time()
[1] "2011-04-06 08:44:01 EDT"
 > as.POSIXlt(x, tz="EDT")
# "EDT" printed as UTC values
[1] "1992-02-27 23:03:20 UTC" "1992-02-27 22:29:56 UTC"
[3] "1992-01-14 01:03:30 UTC" "1992-02-28 18:21:03 UTC"
[5] "1992-02-01 16:56:26 UTC"

But an unambiguous version does return the expected offset. All of  
this can be specific to your system (not provided) and your locale  
setting (also not provided)

 > as.POSIXlt(x, tz="UTC+02")
[1] "1992-02-27 21:03:20 UTC" "1992-02-27 20:29:56 UTC"
[3] "1992-01-13 23:03:30 UTC" "1992-02-28 16:21:03 UTC"
[5] "1992-02-01 14:56:26 UTC"