Html Studio - Html, Css and Script Reference.
The Complete Perl Reference


Home > Perl Reference > Examples > Time & Date

This script adds the date and time to any webpage. But your server must support SSI ( Server Side Incudes )
Below is a example of the SSI comand which you place anywhere on your page where you want the date to be place.

<!--#exec cgi="/cgi-bin/clock.cgi" -->


The Code
Paste the code below into a text editor and save it as clock.pl Upload the script into your cgi bin. Upload it as ASCII.

Please make it so #!/usr/bin/perl is the location of perl on your server.


#!/usr/bin/perl

# Define Variables #

$Display_Week_Day = '1';

$Display_Month = '1';

$Display_Month_Day = '1';

$Display_Year = '1';

$Display_Time = '1';

$Display_Time_Zone = '1';

$Standard_Time_Zone = 'EST';
$Daylight_Time_Zone = 'EDT';

$Display_Link = '1';

# Done #
##############################################################################

@Week_Days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');

@Months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');


print "Content-type: text/html\n\n";

if ($Display_Link != 0) {
print "<a href=\"http://www.worldwidemart.com/scripts/\">";
}

($Second,$Minute,$Hour,$Month_Day,
$Month,$Year,$Week_Day,$IsDST) = (localtime)[0,1,2,3,4,5,6,8];

if ($IsDST == 1) {
$Time_Zone = $Daylight_Time_Zone;
}
else {
$Time_Zone = $Standard_Time_Zone;
}

if ($Second < 10) {
$Second = "0$Second";
}
if ($Minute < 10) {
$Minute = "0$Minute";
}
if ($Hour < 10) {
$Hour = "0$Hour";
}
if ($Month_Day < 10) {
$Month_Day = "0$Month_Day";
}
$Year += 1900;

if ($Display_Week_Day != 0) {
print "$Week_Days[$Week_Day]";
if ($Display_Month != 0) {
print ", ";
}
}

if ($Display_Month != 0) {
print "$Months[$Month] ";
}

if ($Display_Month_Day != 0) {
print "$Month_Day";
if ($Display_Year != 0) {
print ", ";
}
}

if ($Display_Year != 0) {
print "$Year";
if ($Display_Time != 0) {
print " - ";
}
elsif ($Display_Time_Zone != 0) {
print " ";
}
}

if ($Display_Time != 0) {
print "$Hour\:$Minute\:$Second";
if ($Display_Time_Zone != 0) {
print " ";
}
}

if ($Display_Time_Zone != 0) {
print "$Time_Zone";
}

if ($Display_Link != 0) {
print "</a>";
}

exit;


Maintained by Nick Grant < htmlstudio@talk21.com >


Copyright © 2000 Nick Grant. All Rights Reserved.