Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting timein cgi

Status
Not open for further replies.

Keegan

Programmer
May 27, 2001
5
US
How do I get the time?
 
I use this:

Code:
sub Time {

$timeoffset = 0;

($sec,$min,$hour,$mday,$mon,$year) = localtime(time + (3600*$timeoffset));

$hour = &quot;0$hour&quot; if ($hour < 10);
$min  = &quot;0$min&quot; if ($min < 10);
$sec  = &quot;0$sec&quot; if ($sec < 10);
$mday = &quot;0$mday&quot; if ($mday < 10);
$mon  = &quot;0$mon&quot; if ($mon < 10);

$year = 2000 + ($year - 100);

# Date and time variables

$Date = &quot;$mon-$mday-$year&quot;;
$Time = &quot;$hour:$min:$sec&quot;;

}

I hope this helps. :-D - PLEASE GO THERE! WE NEED MORE MEMBERS! :)
 
Another way:

use POSIX;
($Date, $Time) = POSIX::strftime(&quot;%m-%d-%Y%H:%M&quot;,localtime()) =~ m/^(.{10})(.{5})$/;

And yes you are loading the POSIX module, but it is only 20 KBytes.
 
raider - you would load the POSIX module just to use the time thingy? does it give you any advantages over the builtin functions localtime and gmtime? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
The only advantage would be 2 lines of code compared to 10 lines of code. The disadvantage would be the time required to load the POSIX module. I just wanted to point out another way of doing things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top