Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've unsuccessfully been able to coordinate ActivePerl 5.8 with WinXP to report the correct time. The following code:
#!/usr/bin/perl use locale; my $currentTime = gmtime; print "$currentTime\n";
reports Sun Sep 21 21:51:53 2003 upon execution when the time is actually 4:51pm.

When I issue:

perl -V:d_setlocale
I find that that d_setlocale='define';. What have I missed in the documentation?

Thanks.

Replies are listed 'Best First'.
Re: correctly reporting time?
by Zaxo (Archbishop) on Sep 22, 2003 at 00:01 UTC

    Perhaps you want to call localtime instead of gmtime. For me,

    $ perl -e'print scalar(gmtime),$/' Sun Sep 21 23:55:17 2003 $ perl -e'print scalar(localtime),$/' Sun Sep 21 19:55:29 2003 $

    After Compline,
    Zaxo

      Thanks; that did it...
Re: correctly reporting time?
by The Mad Hatter (Priest) on Sep 22, 2003 at 00:02 UTC
    First, from what I understand, calling gmtime should always give you GMT/UTC/Zulu time.

    Second, locale isn't (AFAIK) the right module to use. Try setting $ENV{TZ} to your timezone and then calling localtime. (On some systems, you may need to throw a use POSIX; POSIX::tzset(); in between there.)