localtime (perldoc -f localtime didn't help) 
Author Message
 localtime (perldoc -f localtime didn't help)

Alright, here's another question about localtime that I couldn't find
the
answer for by running "perldoc -f localtime"...  I hope no one minds
toooooo much.  :)

I have the following perl program that when run on the commandline it
returns the correct time, but once it is run through apache the time is
an
hour behind.  This only happens on one of my computers and not the
other two.  I would guess it's some kind of TZ setting or daylight
savings
setting, but I don't know where it would be located at.

Here's the code:

--- Start ---
#!/usr/local/bin/perl -w
use diagnostics;
use strict;

my ($yyyy, $mm, $dd, $hh, $mi, $ss) = (localtime)[5, 4, 3, 2, 1, 0];
$yyyy += 1900;
$mm++;

print "Content-Type: text/html\n\n";
printf "Current date and time is: %2.2d-%2.2d-%4d: %2.2d:%2.2d:%2.2d\n",

$mm, $dd, $yyyy, $hh, $mi, $ss;
--- End ---

Any help would be great!

Bryan



Mon, 10 Dec 2001 03:00:00 GMT  
 localtime (perldoc -f localtime didn't help)

    Arcane> I have the following perl program that when run on the
    Arcane> commandline it returns the correct time, but once it is
    Arcane> run through apache the time is an hour behind.  This only
    Arcane> happens on one of my computers and not the other two.  I
    Arcane> would guess it's some kind of TZ setting or daylight
    Arcane> savings setting, but I don't know where it would be
    Arcane> located at.

     Try using gmtime and see if the time-lapse still occurs. Or try
     print scalar (localtime()) which will print the timezone.



Mon, 10 Dec 2001 03:00:00 GMT  
 localtime (perldoc -f localtime didn't help)

Quote:


>     Arcane> I have the following perl program that when run on the
>     Arcane> commandline it returns the correct time, but once it is
>     Arcane> run through apache the time is an hour behind.  This only
>     Arcane> happens on one of my computers and not the other two.  I
>     Arcane> would guess it's some kind of TZ setting or daylight
>     Arcane> savings setting, but I don't know where it would be
>     Arcane> located at.

>      Try using gmtime and see if the time-lapse still occurs. Or try
>      print scalar (localtime()) which will print the timezone.

Using gmtime shows the correct time in both areas.  print scalar
(localtime()) doesn't return the timezone, but doing print `date` does.
Here is the output of the updated program:

Commandline:

--- Start ---
Content-Type: text/html

Current date and time is: 06-24-1999: 21:29:56<BR>
Current date and time is: 06-24-1999: 15:29:56<BR>
Thu Jun 24 15:29:56 1999<BR>
Thu Jun 24 15:29:56 MDT 1999
<BR>
--- End ---

Web site on same computer:

--- Start ---
Current date and time is: 06-24-1999: 21:30:51
Current date and time is: 06-24-1999: 14:30:51
Thu Jun 24 14:30:51 1999
Thu Jun 24 14:30:51 MST 1999
--- End ---

So somehow this is caused by daylight savings time being on in one of
them!  We're using version 1.3.6 that came with Redhat 6.0 I believe.
Any ideas?

Here is the new source for the program:

--- Start ---
#!/usr/local/bin/perl -w
use strict;
use diagnostics;

print "Content-Type: text/html\n\n";

my ($second, $minute, $hour, $day, $month, $year) = gmtime();
$year += 1900;
$month++;

printf "Current date and time is: %2.2d-%2.2d-%4d:
%2.2d:%2.2d:%2.2d<BR>\n", $month, $day, $year, $hour, $minute, $second;

($second, $minute, $hour, $day, $month, $year) = (localtime);
$year += 1900;
$month++;

printf "Current date and time is: %2.2d-%2.2d-%4d:
%2.2d:%2.2d:%2.2d<BR>\n", $month, $day, $year, $hour, $minute, $second;

print scalar (localtime()) . "<BR>\n";

print `date` . "<BR>\n";
--- End ---

Thanks for the help!

Bryan



Mon, 10 Dec 2001 03:00:00 GMT  
 localtime (perldoc -f localtime didn't help)
[posted and mailed]


: >
: >     Arcane> I have the following perl program that when run on the
: >     Arcane> commandline it returns the correct time, but once it is
: >     Arcane> run through apache the time is an hour behind.  This only
: >     Arcane> happens on one of my computers and not the other two.  I
: >     Arcane> would guess it's some kind of TZ setting or daylight
: >     Arcane> savings setting, but I don't know where it would be
: >     Arcane> located at.
: >
: >      Try using gmtime and see if the time-lapse still occurs. Or try
: >      print scalar (localtime()) which will print the timezone.

: Using gmtime shows the correct time in both areas.  print scalar
: (localtime()) doesn't return the timezone, but doing print `date` does.
: Here is the output of the updated program:

My guess is that the web server didn't properly set TZ. Or that you're
on HP-UX, and /usr/lib/tztab isn't accessible from your CGI program's
environment.

Andrew



Mon, 10 Dec 2001 03:00:00 GMT  
 localtime (perldoc -f localtime didn't help)

Quote:

> I have the following perl program that when run on the commandline it
> returns the correct time, but once it is run through apache the time is
> an
> hour behind.  This only happens on one of my computers and not the
> other two.  I would guess it's some kind of TZ setting or daylight
> savings
> setting, but I don't know where it would be located at.

Try setting  $ENV{'TZ'} to the appropriate vale at the beginning of
your program before using localtime().

You might want to ask on the group comp.infosystems.www.servers.unix
if there are any know workarounds for this in the Apache configuration.

/J\
--

Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>



Wed, 12 Dec 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. why doesn't localtime()[2] work?

2. localtime and Win32: The april fool's bug

3. localtime () - perl's bug ?

4. localtime(time) dosen't work

5. HELP! Problems with localtime()

6. Help with Time::localtime

7. Help with Time::localtime

8. HELP: localtime, days of a month

9. Help with Time::localtime

10. Help to fix the output of date and localtime in CGI

11. localtime() - HELP

12. HELP! Problems with localtime()

 

 
Powered by phpBB® Forum Software