BW
Main Menu
Home
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
Newsletter
Contact Bill
The End
· Sponsors ·
amazon.com
Personal Loans Online
Names Database
Google Optimization
Free Credit Score
Learn Programming
Live Music
Rheumatoid Arthritis
Mortgage Leads
Payday Advance
Debt Consolidation
Bad Credit Loans
Mortgage Refinance
Newsletter Delivery
Mobile Ringtones
Home Loans
Netflix DVD Rentals
Site Design: Bill Weinman
© 1995-2008
W.E. 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:

3:11 am on Thursday, 24 July 2008 in Phoenix, Arizona

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 Phoenix, Arizona\n";

exit;

Very funny, Scotty. Now beam down my clothes.
·/.