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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



Larkdog
User

Sep 2, 2004, 3:25 PM

Post #1 of 2 (794 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)


Code
  

my @time = localtime;

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

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



My modified code (correct time)


Code
   



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
www.MrLarkins.com


davorg
Thaumaturge / Moderator

Sep 14, 2004, 3:52 AM

Post #2 of 2 (686 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.


Code
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
http://www.dave.org.uk/
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