editor Posted November 11, 2005 Share Posted November 11, 2005 I have a perl script that records member logins on my Web site. Here's part of the code: _____ open(FILE, ">>$log_file"); {($sec,$min,$hour,$day,$month) = localtime(); $month++; if ($hour < 10) { $hour = "0$hour"; } if ($min < 10) { $min = "0$min"; } } if ($password ne "xxxx") { print FILE "$month/$day $hour:$min $password $ENV{'REMOTE_ADDR'}\n"; close(FILE); _____ The problem is that the time printed to the log file for each login is one hour ahead of the time where I live. Presumably, localtime() on the server where my Web site resides (Server 24) is Eastern Time, whereas I live in the Central Time zone. What changes could I make to the script so that the time it prints to the log file matches my own time zone? Quote Link to comment Share on other sites More sharing options...
TweezerMan Posted November 11, 2005 Share Posted November 11, 2005 Try this code out and see if it works for you: >use DateTime; open(FILE, ">>$log_file"); my $dt = DateTime->now(time_zone => 'America/Chicago'); if ($password ne "xxxx") { print FILE $dt->strftime("%m/%d %H:%M") . " $password $ENV{'REMOTE_ADDR'}\n"; close(FILE); Quote Link to comment Share on other sites More sharing options...
editor Posted November 11, 2005 Author Share Posted November 11, 2005 Try this code out and see if it works for you: >use DateTime; open(FILE, ">>$log_file"); my $dt = DateTime->now(time_zone => 'America/Chicago'); if ($password ne "xxxx") { print FILE $dt->strftime("%m/%d %H:%M") . " $password $ENV{'REMOTE_ADDR'}\n"; close(FILE); I appreciate the help. However, the modified script generates a "Premature end of script headers" error. Quote Link to comment Share on other sites More sharing options...
TweezerMan Posted November 11, 2005 Share Posted November 11, 2005 Silly me! I tested the code on my local PC, where it worked fine, and I thought it would work just as well on the TCH server without further testing. I had to have the Help Desk install the DateTime and DateTime::TimeZone modules on my server before the code would work correctly. Submit a ticket to the Help Desk and ask them to install the DateTime and DateTime::TimeZone perl modules on your server, then try your script again. Quote Link to comment Share on other sites More sharing options...
editor Posted November 11, 2005 Author Share Posted November 11, 2005 Submit a ticket to the Help Desk and ask them to install the DateTime and DateTime::TimeZone perl modules on your server, then try your script again. I submitted the ticket, the modules were installed swiftly, and the script now works beautifully! Thanks again for all your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.