Server Side Include Date & Time Display Script
TextClock is a Perl CGI script designed to work with Server Side Includes (SSI), providing dynamic date and time display on your web pages. With multiple formatting options, you can show the current time, date, or both in various styles to match your site's design.
TextClock is one of the simplest yet most useful CGI scripts from the early web era. It works through Server Side Includes, allowing webmasters to display dynamic date and time information on otherwise static HTML pages.
| File | Description |
|---|---|
textclock.pl |
Main Perl script that displays the current time and date |
README |
Installation instructions and configuration guide |
Loading...
JavaScript recreation of TextClock outputDisplay dates in various formats including full month names, abbreviated formats, numeric dates, and custom combinations.
Show time in 12-hour or 24-hour format, with or without seconds, and include timezone information.
Configure output format through URL parameters, making it easy to use different formats on different pages.
Works well with Server Side Includes on Apache and other SSI-enabled web servers.
Minimal server resources required. The script is small and executes quickly with negligible overhead.
Optionally wrap the output in a hyperlink to any URL, creating clickable date/time stamps.
TextClock supports numerous display formats controlled by the format parameter:
| Format Code | Description | Example Output |
|---|---|---|
%a |
Abbreviated weekday name | Sun, Mon, Tue |
%A |
Full weekday name | Sunday, Monday, Tuesday |
%b |
Abbreviated month name | Jan, Feb, Mar |
%B |
Full month name | January, February, March |
%d |
Day of month (01-31) | 01, 15, 28 |
%e |
Day of month (1-31, no padding) | 1, 15, 28 |
%H |
Hour (00-23) | 00, 13, 23 |
%I |
Hour (01-12) | 01, 06, 12 |
%M |
Minute (00-59) | 00, 30, 59 |
%S |
Second (00-59) | 00, 45, 59 |
%m |
Month (01-12) | 01, 06, 12 |
%p |
AM/PM indicator | AM, PM |
%y |
Year (2-digit) | 99, 00, 25 |
%Y |
Year (4-digit) | 1999, 2000, 2025 |
%Z |
Timezone name | EST, PST, UTC |
Options +Includes to your .htaccess or httpd.conf.
textclock.pl to your cgi-bin directory.
#!/usr/bin/perl).
chmod 755 textclock.pl
<!-- Display full date and time -->
<!--#exec cgi="/cgi-bin/textclock.pl"-->
<!-- Display with custom format -->
<!--#exec cgi="/cgi-bin/textclock.pl?format=%A,+%B+%d,+%Y+-+%I:%M:%S+%p+%Z"-->
<!-- Display date only -->
<!--#exec cgi="/cgi-bin/textclock.pl?format=%B+%d,+%Y"-->
<!-- Display time only (24-hour format) -->
<!--#exec cgi="/cgi-bin/textclock.pl?format=%H:%M:%S"-->
<!-- Display time only (12-hour format) -->
<!--#exec cgi="/cgi-bin/textclock.pl?format=%I:%M+%p"-->
<!-- Display with link -->
<!--#exec cgi="/cgi-bin/textclock.pl?format=%A,+%B+%d,+%Y&link=http://example.com/"-->
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
use CGI;
my $cgi = CGI->new;
my $format = $cgi->param('format') || '%A, %B %d, %Y - %I:%M:%S %p %Z';
my $link = $cgi->param('link') || '';
# Security: sanitize format string
$format =~ s/[^\w\s%:,\-\/\.]//g;
# Generate the time string
my $time_string = strftime($format, localtime);
# Output
print $cgi->header('text/html');
if ($link) {
# Sanitize link
$link =~ s/[<>"']//g;
print qq{$time_string};
} else {
print $time_string;
}
exit 0;
<?php
/**
* TextClock - PHP Version
* Display current date and time with customizable format
*/
// Default format
$format = $_GET['format'] ?? 'l, F j, Y - h:i:s A T';
$link = $_GET['link'] ?? '';
// Security: convert strftime-style format to PHP date format
// This is a simplified conversion - full implementation would need more mappings
$format_map = [
'%A' => 'l', // Full weekday
'%a' => 'D', // Abbreviated weekday
'%B' => 'F', // Full month
'%b' => 'M', // Abbreviated month
'%d' => 'd', // Day (01-31)
'%e' => 'j', // Day (1-31)
'%H' => 'H', // Hour (00-23)
'%I' => 'h', // Hour (01-12)
'%M' => 'i', // Minute
'%S' => 's', // Second
'%m' => 'm', // Month (01-12)
'%p' => 'A', // AM/PM
'%Y' => 'Y', // Year (4-digit)
'%y' => 'y', // Year (2-digit)
'%Z' => 'T', // Timezone
'+' => ' ', // Plus signs to spaces
];
$php_format = strtr($format, $format_map);
$time_string = date($php_format);
// Output
if (!empty($link)) {
$link = htmlspecialchars($link, ENT_QUOTES, 'UTF-8');
echo "<a href=\"{$link}\">{$time_string}</a>";
} else {
echo $time_string;
}
?>
/**
* TextClock - JavaScript Version
* Display current date and time with customizable format
*/
class TextClock {
constructor(element, options = {}) {
this.element = typeof element === 'string'
? document.querySelector(element)
: element;
this.options = {
format: 'full',
link: null,
updateInterval: 1000,
locale: 'en-US',
...options
};
this.init();
}
init() {
this.update();
if (this.options.updateInterval > 0) {
setInterval(() => this.update(), this.options.updateInterval);
}
}
getFormatOptions() {
const formats = {
'full': {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
timeZoneName: 'short'
},
'date': {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
},
'time': {
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
},
'short': {
year: 'numeric',
month: 'short',
day: 'numeric'
},
'iso': {
year: 'numeric',
month: '2-digit',
day: '2-digit'
}
};
return formats[this.options.format] || formats['full'];
}
update() {
const now = new Date();
let timeString;
if (this.options.format === 'iso') {
timeString = now.toISOString().split('T')[0];
} else {
timeString = now.toLocaleDateString(
this.options.locale,
this.getFormatOptions()
);
}
if (this.options.link) {
this.element.innerHTML = `<a href="${this.options.link}">${timeString}</a>`;
} else {
this.element.textContent = timeString;
}
}
}
// Usage examples:
// Basic usage
new TextClock('#clock');
// With options
new TextClock('#clock', {
format: 'full',
link: 'https://example.com/',
locale: 'en-US',
updateInterval: 1000
});
// Date only (no live update)
new TextClock('#date', {
format: 'date',
updateInterval: 0
});
// Time only
new TextClock('#time', {
format: 'time'
});
Main Perl script that displays the current time
Installation instructions and detailed setup guide
<!--#command parameter="value"-->. Common uses include displaying the current date, including other files, or showing the last modification time of a document.
Options +Includes to your .htaccess file or virtual host configuration. You also need to tell Apache which files to parse for SSI, typically with: AddHandler server-parsed .shtml or AddOutputFilter INCLUDES .html to parse all HTML files.
$ENV{TZ} = 'America/New_York'; at the beginning of the script. Note that available timezone names depend on your server's operating system.
use POSIX qw(locale_h strftime); setlocale(LC_TIME, "de_DE"); This would display German day and month names. The locale must be installed on your server.
Date object with Intl.DateTimeFormat for client-side display with automatic localization, PHP's date() and DateTime classes for server-side rendering, or template engine functions in frameworks like Laravel, Django, or Rails. These modern approaches offer better internationalization, timezone handling, and don't require SSI to be enabled.