I recently had to add some code that sets $ENV{TZ} to the correct local time. (Date::Manip requires this, and it wasn't already in my ENV on windows.) I've noticed that since doing that, when I call one perl script from another the localtime incorrectly returns GMT in the called script.
$ENV{'TZ'} = '-0400'; # also tried 'US/Eastern' with same result. print qq{---- $ENV{'COUNT'} ---- TZ: $ENV{'TZ'} localtime: } . scalar(localtime) . "\n"; $ENV{'COUNT'}++; exit if $ENV{'COUNT'} > 3; system("C:\\perl\\bin\\perl.exe C:\\cgi\\test");
The result is:
C:\FootPrints1\cgi>C:\perl\bin\perl.exe C:\cgi\test ---- ---- TZ: -0400 localtime: Thu Sep 6 10:46:07 2007 ---- 1 ---- TZ: -0400 localtime: Thu Sep 6 14:46:07 2007 ---- 2 ---- TZ: -0400 localtime: Thu Sep 6 14:46:07 2007 ---- 3 ---- TZ: -0400 localtime: Thu Sep 6 14:46:07 2007
I'm using ActiveState 5.8.8. When I try the same on Solaris with 5.8.1 it always shows the correct local time. I tried the following code after setting ENV{TZ}, but it had no effect on the result:
use POSIX(); POSIX::tzset();
Any ideas how I can make localtime give me the local time (while still setting ENV{TZ} to keep Date::Manip happy)? What settings does localtime depend on?

Thanks, Joe


In reply to ENV{TZ} and localtime? (inconsistent time in child script) by blahblahblah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.