[Haskell-cafe] timezone-series and timezone-olson
gale at sefer.org
Sun Mar 27 14:16:50 CEST 2011
I am copying this response to the Haskell Cafe mailing list.
Manfred Lotz wrote:
> ...I'm trying to figure out how to use your
> packages to get the time in a different timezone.
> Do you have an example how to do that? What I want for example is to
> provide the timezone preferably like this: US/Eastern, and get the time
> information like for example this:
> US/Eastern DST EDT 2011.03.27 05:20:52
> The pieces I like to get are: Summertime indicator, TZ abbrev and the
> date resp. time in that timezone.
If you are willing to hard-code the offset of the timezone, you
don't need my packages. You only need them if you need your
program to reflect accurately whether summer time is/was in effect
at the given time at the given location, or if the timezone changed
at some time in history.
I assume that you are starting with a UTCTime object, constructed
in one of the usual ways using the time package.
Get the timezone information provided by the operating system.
On anything other than Windows, that means reading the timezone
file for that zone. On Windows the information is in the registry,
but unfortunately we don't have an interface for reading it from there
yet. The best I can suggest for now is to copy timezone files from
a non-Unix computer.
Assuming you have the timezone file that you need - let's say it
is in the directory /usr/share/zoneinfo as typical for Linux and
Mac - here is how to code it:
tzs <- getTimeZoneSeriesFromOlsonFile "/usr/share/zoneinfo/America/New_York"
let usEastern = utcToLocalTime' tzs utc
Then, to format the time as you require, use the formatTime function from
the time package.
Hope this helps,
More information about the Haskell-Cafe