Operating System - Microsoft
1752275 Members
5047 Online
108786 Solutions
New Discussion юеВ

Perl Script /Time function giving different results

 
SOLVED
Go to solution
ABS_1
Regular Advisor

Perl Script /Time function giving different results

Hi,

Here is a simple perl script that displays the current system time:
==============================================
($seconds, $minutes, $hour, $dayofmonth, $month, $year, $dayofweek, $dayofyear, $dst) = localtime(time);

print $seconds, " Second\n";
print $minutes, " Minute\n";
print $hour, " Hour\n";
print $dayofmonth, " Day of Month\n";
print $month, " Month\n";
print $year, " Year\n";
print $dayofweek, " Day of week\n";
print $dayofyear, " Day of year\n";
print $dst, " DST\n";
==============================================

When executed on a Windows server, it gives the correct "hour" value, but, when executed on another windows server (which is in the same timezone and physical location as the first server), it gives an "hour" value that is ahead by 5 hours.

Windows Admins are sure that the OS setup (as far as time/timezone/etc) is correct. Why would I be seeing this difference? Would this be something Windows related or the Perl related?
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Perl Script /Time function giving different results

First, make certain that the two system's time are set correctly by using the Perl gmtime() function rather than localtime(). The output list is exactly the same except for dst -- which should be omitted.

If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Perl Script /Time function giving different results

Hi:

This is certainly related to your OS configuration and is NOT a Perl "problem".

Perl uses the standard libc library routines which in turn are sensitive to the environment's timezone.

You might examine what each server shows for:

# perl -le 'print join " =L:G= ", scalar localtime, scalar gmtime'

Regards!

...JRF...



ABS_1
Regular Advisor

Re: Perl Script /Time function giving different results

Hi Clay,

With localtime(), I get the following output on the problem windows server:

27 Second
6 Minute
18 Hour
3 Day of Month
6 Month
107 Year
2 Day of week
183 Day of year
1 DST

With gmtime(), I get the following output on the problem windows server:

59 Second
6 Minute
17 Hour
3 Day of Month
6 Month
107 Year
2 Day of week
183 Day of year
0 DST
ABS_1
Regular Advisor

Re: Perl Script /Time function giving different results

Hi James,

When executing the command you suggested, I get the following error:


F:\usr\OV\conf\OpC>c:\perl\bin\perl -le 'print join " =L:G= ", scalar localtime,
scalar gmtime'
Can't find string terminator "'" anywhere before EOF at -e line 1.
Dennis Handly
Acclaimed Contributor

Re: Perl Script /Time function giving different results

What is the gmtime on both the good and bad servers?

If you posted your reply within 13 minutes of your run, the gmtime is fine but your timezone for local time is for Europe, 1 hour ahead of GMT. Or 5 hours ahead of EDT.
ABS_1
Regular Advisor

Re: Perl Script /Time function giving different results

Hi Dennis,

Here is the gmtime (using the gmtime() function) on the good server:

46 Second
36 Minute
17 Hour
3 Day of Month
6 Month
107 Year
2 Day of week
183 Day of year
0 DST

Here is the gmtime (using the gmtime() function) on the bad server:

42 Second
37 Minute
17 Hour
3 Day of Month
6 Month
107 Year
2 Day of week
183 Day of year
0 DST


Both have been posted here within seconds of running the script.
Dennis Handly
Acclaimed Contributor

Re: Perl Script /Time function giving different results

>Both have been posted here within seconds of running the script.

Your GMT time on both is fine. If this was a UNIX system, it would mean your timezone setting was bad on the one. Since this is Windows, you should have started your thread there.