CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
A shorter version?



Sep 2, 2004, 3:25 PM

Post #1 of 2 (1248 views)
A shorter version? Can't Post

Ok, Davorg wrote a timestamp code for me earlier, but it is an hour fast. I went ahead and modified the code so that it stamps the correct time. But I wonder is there a shorter way to do it?

Original code (hour fast)


my @time = localtime;

my $EntryDate = strftime '%B %d, %Y', @time;

my $EntryTime = strftime '%H:%M', @time;

My modified code (correct time)


my @time = localtime;

my $EntryDate = strftime '%B %d, %Y', @time;

my $Hour = strftime '%H', @time;

my $Minute = strftime '%M', @time;

my $AdjustedHour = $Hour-1;

my $EntryTime = "$AdjustedHour:$Minute";

using the POSIX 'strftime', of course

Thaumaturge / Moderator

Sep 14, 2004, 3:52 AM

Post #2 of 2 (1140 views)
Re: [Larkdog] A shorter version? [In reply to] Can't Post

Well, I'd recommend working out why your server's clock is an hour wrong (is it in a different timezone? can you fix it by setting the TZ environment variable?)

But if you can't do either of those, the easiest way is to just fix the parameters that you pass to "localtime". "localtime" returns an array based on the time that you pass it. If you don't pass a time then it uses the current time. If your time is consistantly an hour fast then use this instead.

my @time = localtime(time - 3600);

"time" returns the current time (in seconds since the start of Jan 1st 1970) and you simply subtract the number of seconds in an hour).

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives