Hello, I'm trying to convert times in the EST/EDT (New York) format to times in the GMT/BST (London) and UTC+9 format (Tokyo). That is, if I know what time it is in New York, what is local time in London and Tokyo? Ex: Here's the conversion from New York EST/EDT time to London's GMT/BST time zone for three days in 2007. Note that the US and London change to daylight savings on different days (Tokyo doesn't use daylight savings at all), so this conversion is non-trivial. 2007-03-01 12:00:00 EST = 2007-03-01 17:00:00 GMT 2007-03-15 12:00:00 EDT = 2007-03-01 16:00:00 GMT 2007-04-01 12:00:00 EDT = 2007-03-01 17:00:00 BST Is any of the time zone/daylight savings information coded up somewhere? Thanks, Robert Robert McGehee, CFA Geode Capital Management, LLC One Post Office Square, 28th Floor | Boston, MA | 02109 Tel: 617/392-8396 Fax:617/476-6389 mailto:robert.mcgehee at geodecapital.com This e-mail, and any attachments hereto, are intended fo...{{dropped:11}}
Well, I'll go ahead and (partially) answer my own question. This seems to do the trick for Britain:> as.POSIXlt(as.POSIXct("2007-04-01 12:00:00"), tz="GB")[1] "2007-04-01 17:00:00 BST" (And it also points out that I got my conversions wrong in my toy example!) I had originally tried this by setting the 'tz' argument using 'as.POSIXct', but this didn't work for some reason (hence the post)> as.POSIXct(as.POSIXct("2007-04-01 12:00:00"), tz="GB")[1] "2007-04-01 12:00:00 EDT" Hopefully I can figure out from the links what the Tokyo time zone is called. Sorry for the noise!> R.version_ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 6.1 year 2007 month 11 day 26 svn rev 43537 language R version.string R version 2.6.1 (2007-11-26)>-----Original Message----- From: McGehee, Robert Sent: Monday, April 28, 2008 4:27 PM To: r-help Subject: time zone conversion Hello, I'm trying to convert times in the EST/EDT (New York) format to times in the GMT/BST (London) and UTC+9 format (Tokyo). That is, if I know what time it is in New York, what is local time in London and Tokyo? Ex: Here's the conversion from New York EST/EDT time to London's GMT/BST time zone for three days in 2007. Note that the US and London change to daylight savings on different days (Tokyo doesn't use daylight savings at all), so this conversion is non-trivial. 2007-03-01 12:00:00 EST = 2007-03-01 17:00:00 GMT 2007-03-15 12:00:00 EDT = 2007-03-01 16:00:00 GMT 2007-04-01 12:00:00 EDT = 2007-03-01 17:00:00 BST Is any of the time zone/daylight savings information coded up somewhere? Thanks, Robert Robert McGehee, CFA Geode Capital Management, LLC One Post Office Square, 28th Floor | Boston, MA | 02109 Tel: 617/392-8396 Fax:617/476-6389 mailto:robert.mcgehee at geodecapital.com This e-mail, and any attachments hereto, are intended fo...{{dropped:11}}
The POSIXct/lt functions do this (provided your OS is up to it).> x <- c("2007-03-01 12:00:00", "2007-03-15 12:00:00","2007-04-01 12:00:00")> xx <- as.POSIXct(x, tz="EST5EDT") > format(xx, tz="Europe/London")[1] "2007-03-01 17:00:00" "2007-03-15 16:00:00" "2007-04-01 17:00:00"> format(xx, "%Y-%m-%d %H:%M:%S %Z", tz="Europe/London")[1] "2007-03-01 17:00:00 GMT" "2007-03-15 16:00:00 GMT" [3] "2007-04-01 17:00:00 BST" That's Linux, but R 2.7.0 under Windows can do this too (except it labels time zones by Windows' names in the last case). On Mon, 28 Apr 2008, McGehee, Robert wrote:> Hello, > > I'm trying to convert times in the EST/EDT (New York) format to times in > the GMT/BST (London) and UTC+9 format (Tokyo). That is, if I know what > time it is in New York, what is local time in London and Tokyo? > > Ex: > Here's the conversion from New York EST/EDT time to London's GMT/BST > time zone for three days in 2007. Note that the US and London change to > daylight savings on different days (Tokyo doesn't use daylight savings > at all), so this conversion is non-trivial. > > 2007-03-01 12:00:00 EST = 2007-03-01 17:00:00 GMT > 2007-03-15 12:00:00 EDT = 2007-03-01 16:00:00 GMT > 2007-04-01 12:00:00 EDT = 2007-03-01 17:00:00 BSTDon't think so .....> > Is any of the time zone/daylight savings information coded up somewhere? > > Thanks, > Robert > > Robert McGehee, CFA > Geode Capital Management, LLC > One Post Office Square, 28th Floor | Boston, MA | 02109 > Tel: 617/392-8396 Fax:617/476-6389 > mailto:robert.mcgehee at geodecapital.com > > > > This e-mail, and any attachments hereto, are intended fo...{{dropped:11}} > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595