Re: [R] time zone problems

From: Stephen Tucker <>
Date: Wed 04 Apr 2007 - 08:28:24 GMT

Hi Marc,

This R Help Desk article was very helpful for me: Gabor Grothendieck and Thomas Petzoldt

And Gabor noted subsequent changes in behavior of POSIXt classes since the aforementioned R News publication:

(1) (2)

Basically, strptime() converts your character object to an POSIXlt object, which may have a tzone attribute but it is ignored by everything- so you have to convert it to POSIXct by as.POSIXct(format(myDateTimeObject),"GMT"). But plot() will still try to make your figures according to system time ("").

Here are two possible solutions (if all of your work is in GMT):

Sys.putenv(TZ = "GMT")
## your work
## (shouldn't have to use tzone.err)
Sys.putenv(TZ = "")

Use 'chron' objects as suggested in the R newsletter. This object class does not include any time-zone information, so simplifies things.

Best regards,


> Folks,
> I'm having trouble with how datetime objects with time zones are set
> and plotted. This may be the result of my running R (2.4.0) on a
> Windoze XP box. Perhaps not. Here are two example problems I need
> advise on if you have time:
> 1) I collect data with dates (often as a fractional day of year) in
> UTC. Using strptime to create date time objects appears to force the
> data into the local time zone (including daylight time) of my
> machine. Setting the tz="UTC" or "GMT" inside strptime seems to be
> ignored. I made the following cumbersome work around:
> foo$date=strptime((paste(yr,DOY), 0, 0), format="%Y %j %H %M",tz="") + 0
> foo$date=foo$date-tzone.err
> attributes(foo$date)$tzone="GMT"
> Am I missing something obvious or is this a problem with Windoze?
> 2) Once I have the data in GMT, I try to plot it using the standard
> plot command but it converts the data back to local time before
> making the plot. Now the work around is:
> plot(foo$date+tzone.err,foo$var, xlab="Date(GMT)")
> Very frustrating... I've read the help pages but can't find answers
> to these issues. Any help?
> Best regards,
> Marc
> ______________________________________________
> mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
> mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed Apr 04 18:32:31 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 04 Apr 2007 - 09:31:03 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.