sloppycode.net
Date and time sample
Details about the format of dates and time in Perl.
Home
›
Code snippets
›
Perl (CGI)
›
Date and time sample
How to get the date and time and format it.
#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); #-- Localtime format ----------------------------------- # 0 1 2 3 4 5 6 7 8 # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) # sec = second # min = minute # hour = hour # mday = day in the month (1 ... 28/30/31) # mon = month (1-12) # year = year expressed in years since 1900, so 4 digit representation you add 1900 # wday = weekday (0 = Sunday) # yday = the day of the year, 0-365 # isdst = true/false depending on whether you want the time to display in daylight saving hours #-- Date/Time ----------------------------------- @mytime = localtime(time); $hour = $mytime[2] ; $minute = $mytime[1]; $second = $mytime[0]; $day = $mytime[3]; $month = ($mytime[4] +1); # Month starts from 0, e.g. January is 0 $year = ($mytime[5] + 1900); # year is expressed in years since 1900, so 4 digit representation you add 1900 #-- Output ----------------------------------- print "Content-type: text/html\n\n"; print "<html>\n"; print "<body>\n"; print $hour. ":" .$minute . ":" .$second ."<br> \n"; print $day . "/" .$month . "/" . $year ."<br> \n"; print "</body>\n"; print "</html>";
{Name}
Says:
{Date}
{Text}
› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search