Skip to content
Prev 82212 / 398503 Next

Automatic time zone conversion

Hi,

Thanks for the help. Your method does work. However, I am not sure
if my R give CST a correct offset to timezone or at least display it 
normally.
 > cdate
[1] "2000-05-11_01:00:00.0000\005\003"
 > format(as.POSIXct(paste(as.character(strptime(cdate,format=
+"%Y-%m-%d_%H:%M:%S")),"GMT")),tz="CST",format="%Y%m%d %H:%M %Z")
[1] "20000510 17:00 CST"
 > as.POSIXct(as.character(strptime(cdate,format="%Y-%m-%d_%H:%M:%S")),
+ tz="CST")+(8*3600)
[1] "2000-05-11 09:00:00 CST"

 > x <- as.POSIXct(chartr("_", " ", cdate), tz = "GMT")
 > attr(x, "tzone") <- NULL
 > x
[1] "2000-05-11 09:00:00 CST"

One thing is strange here. When I tried to find out what the offset is in R.
 > R.version.string
[1] "R version 2.2.0, 2005-10-06"
 > format(Sys.time(),format="%Z %z")
[1] "CST +0000"
While under command line(fedora core 3), my system display a different 
offset.
$date +"%Z %z"
CST +0800

Thanks again for the help and best regard,

Simon
Gabor Grothendieck wrote: