Displaying the Current Date

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email

First, a typical CGI date.cgi which displays the local date and time, does two things:

* Calculates the current time

* Displays the time

The most challenging part of the program will be to figure out how to calculate the time, so we'll begin there. In Perl, calculating the date and time is easy.. Shown below is the Perl code for printing the clate.

($sec, $min, $h, $day, $mon, $y, $week, $dayofyear, $isDST) =localtime(time())

$mon ++;

print "$day/$mon/$y and time is > $h $min $sec"),

The localtime() function converts the value returned by the system's time function into familiar time components such as day, month, year, and so of Now that you know how to calculate and print the current local time, you want to incorporate this into a CGI program. Instead of printing the date to the screen you want to print it to the Web browser.

#print CGI header
print "Content-Type:text/html\n\n;
($sec,$min,$h,$day,$mon,$week,$dayofyear,$isDST)=localtime(time());
$mon++;
#now print the date and time
print"<html><head>\n";
print"<title>Current Date and Time</title>\n;
print"<head><body>\n";
print"<h1>The date is now</h1>\n";
print"<p>Date is $day/$month/$y and time is $h-$min-$sec</p>\n";
print"</body>\n</html>\n";



Domain Name Search

www.


Copyright (C) 2007. Web Domain design hosting. All rights reserved.