BW
Main Menu
Home
Contact Bill
lynda.com FAQ
Facebook
Linked In
Twitter
AMTP
Bio
Hire Bill
Bill’s Music
BW Whois
Boulder Pledge
UBE-Related
Blog
CGI Scripts
CMS Project
Music DB
Creative HTML
The CGI Book
Perl Book
BillyDos
Privacy
The End
· Sponsors ·
lynda.com video tutorials
amazon.com
Rheumatoid Arthritis
Site Design: Bill Weinman

CGI Scripts by Bill Weinman

bw-datetime

This is a simple "include script" for displaying the date and time on a web page. It is run from a server-side include (SSI).

On an Apache server you put something like this in your page:

  <!--#include virtual="/bw-datetime/bw-datetime.cgi" -->

The result should be something like this:

4:19 am on Monday, 27 October 2025 in Las Vegas, Nevada

Of course you can modify the text at the bottom of the script.

Here is the source code for bw-datetime.cgi. Copy/paste this code into your text editor, and make sure that the line

#!/usr/bin/perl -w
is the first line in the file.


#!/usr/bin/perl -w
# 
# bw-datetime.cgi 
#
# Show the date and time on a web page.
#
# Copyright 2003 by Bill Weinman [http://bw.org/]
#
# The author grants permission to use and modify this program as you like. 
# All other rights and ownership are reserved by the author. 
#

use strict;

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

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my @days = qw( 
  Sunday Monday Tuesday Wednesday Thursday Friday Saturday 
  );
my @months = qw ( 
  January February March April May June July 
  August September October November December 
  );

my $dayofweek = $days[$wday];
my $month = $months[$mon];
$year = $year + 1900;

my $meridian = ($hour > 11) ? "pm" : "am";
my $hours = ($hour > 12) ? ($hour - 12) : $hour;
my $minutes = sprintf("%02d", $min);
my $seconds = sprintf("%02d", $sec);

print 
  "${hours}:${minutes} ${meridian} " .
  "on ${dayofweek}, ${mday} ${month} ${year} " .
  "in Las Vegas, Nevada\n";

exit;

It was once believed that if a million monkeys pounded on a million keyboards for an indefinite length of time, they would produce the complete works of Shakespeare. Today, thanks to the Internet, we know that this is not true.
At BHG Worldwide Headquarters it is now nineteen past four, on Monday, 27 October 2025.
·/.