[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: time zone for strftime
From: |
Eli Zaretskii |
Subject: |
Re: time zone for strftime |
Date: |
Thu, 22 Jul 2021 09:32:25 +0300 |
> Date: Wed, 21 Jul 2021 21:55:53 -0400
> From: "Andrew J. Schorr" <aschorr@telemetry-investments.com>
> Cc: help-gawk@gnu.org
>
> On Wed, Jul 21, 2021 at 09:51:20PM -0400, Andrew J. Schorr wrote:
> > On Wed, Jul 21, 2021 at 08:30:45PM -0500, Peng Yu wrote:
> > > https://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html
> > >
> > > I don't see a way to specify a time zone for strftime when converting
> > > an epoch time to the time zone time. Is there a way to do it? Thanks.
> >
> > bash-4.2$ gawk 'BEGIN {t = systime(); ENVIRON["TZ"] = "US/Central"; print
> > strftime("%c", t); ENVIRON["TZ"] = "US/Eastern"; print strftime("%c", t)}'
> > Wed 21 Jul 2021 08:50:54 PM CDT
> > Wed 21 Jul 2021 09:50:54 PM EDT
>
> Although I'm not certain whether that works on non-Unix platforms...
It does, sort of, with two restrictions:
. only simple TZ strings are accepted, like "CET-6CDT" (and the rules
for DST switches are hardcoded in the MS runtime as they were many
years ago)
. you can only set ENVIRON["TZ"] once in each Gawk program; the
subsequent ones are ignored
D:\usr\eli>gawk "BEGIN {t = systime(); ENVIRON[\"TZ\"] = \"CET+2CDT\"; print
strftime(\"%c\", t); ENVIRON[\"TZ\"] = \"EST-5EDT\"; print strftime(\"%c\", t)}"
7/22/2021 8:19:46 AM
7/22/2021 8:19:46 AM