Re: Determine Time in other Time Zone - Mailing list pgsql-general

From Marc Wrubleski
Subject Re: Determine Time in other Time Zone
Date
Msg-id 3AC2C3C6.D4D61D6B@sorexsoftware.com
Whole thread Raw
In response to Re: Determine Time in other Time Zone  ("Russell Hires" <rhires@earthlink.net>)
List pgsql-general
Hi Will,

I am trying to get the time in another timezone as well, and I have it pinned down
in Linux as to a couple ways to do it.

The first is to write c-code that sets a TZ environment variable to the desired
time zone, gets the time (via ctime or localtime) and then switches the TZ
environment variable back. This is NOT efficient as you can imagine, but it works,
and returns accurate values (even accounting for Daylight Saving Time I believe).

The other option I will be looking into is to use the tzfile functions within linux
to read the desired time zone information and to calculate the time zone's time
based on the results from tzfile. tzfile is the program that reads the time zone
information from the /usr/share/zoneinfo files. This would be somewhat more
efficient, but either way, when you are reading the time zone information from the
disk, it won't be very fast.

Hope it helps.

Marc Wrubleski

will trillich wrote:

> Doug McNaught wrote:
> >
> > "Russell Hires" <rhires@earthlink.net> writes:
> >
> > > Second, perhaps this sort of problem has been solved via the ntp software?
> > > ntp polls various time servers. Perhaps there is a way to call a timeserver
> > > that is local to where ever the users are logging in from.
> >
> > NTP keeps time in UTC.  Translation into local time is the
> > responsibility of the client.  So that won't help much.
> >
> > Translating times between time zones is a hard problem.  One thing to
> > look at is the timezone code that is shipped with free Unices
> > (BSD/Linux) as it comes with a database of timezones with their
> > offsets and DST rules.
>
> it SHOULD be simple, if you have access to what you need:
>
>         -- convert originaltime to localtime:
>         localTime = originalTime - originalTimeZone + localTimeZone
>
> isn't there any quickie utility to deliver such variables? maybe at the
> shell/scripting level? this is *nix, after all...
>
> --
> mailto:will@serensoft.com
> http://www.dontUthink.com/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)


pgsql-general by date:

Previous
From: "Randall F. Kern"
Date:
Subject: RE: full table scan on 'select max(value) from table'?
Next
From: Soma Interesting
Date:
Subject: timestamp/function question