Re: Determine Time in other Time Zone

From: Marc Wrubleski <mlwruble(at)sorexsoftware(dot)com>
To: will(at)dontUthink(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Determine Time in other Time Zone
Date: 2001-03-29 05:10:31
Message-ID: 3AC2C3C6.D4D61D6B@sorexsoftware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)earthlink(dot)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(at)serensoft(dot)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(at)postgresql(dot)org)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Soma Interesting 2001-03-29 05:55:58 timestamp/function question
Previous Message Randall F. Kern 2001-03-29 04:59:53 RE: full table scan on 'select max(value) from table'?