Frequently asked questions about the Text Clock script.
Edit the format string in the script.
The Text Clock uses Perl's strftime format codes. Find the format string in the script and customize it:
%H - Hour (00-23)
%I - Hour (01-12)
%M - Minute (00-59)
%S - Second (00-59)
%p - AM/PM
%A - Full weekday name
%B - Full month name
%d - Day of month (01-31)
%Y - Year (4 digits)
| Format String | Output |
|---|---|
%H:%M:%S |
14:30:45 |
%I:%M %p |
02:30 PM |
%A, %B %d, %Y - %I:%M %p |
Monday, December 17, 2025 - 02:30 PM |
Set the TZ environment variable.
The Text Clock displays server time. To show a different timezone, set the TZ variable in your script:
$ENV{'TZ'} = 'America/New_York'; # Eastern Time
$ENV{'TZ'} = 'America/Los_Angeles'; # Pacific Time
$ENV{'TZ'} = 'America/Chicago'; # Central Time
$ENV{'TZ'} = 'Europe/London'; # UK Time
$ENV{'TZ'} = 'Asia/Tokyo'; # Japan Time
Use the standard timezone database (tz database) names. Search for "tz database" online for a complete list.
Yes, use meta refresh or JavaScript.
The CGI script shows the time when executed. To update automatically, you have several options:
<meta http-equiv="refresh" content="1">
Refreshes entire page every second. Simple but causes flicker.
Use JavaScript to update the clock client-side without reloading.
More efficient and no flicker.
Use AJAX to fetch new time from the CGI script without reloading the page.
setInterval(function() {
fetch('/cgi-bin/textclock.cgi')
.then(response => response.text())
.then(data => document.getElementById('clock').innerHTML = data);
}, 1000);
Use %I instead of %H and add %p for AM/PM.
Change your format string to use 12-hour time codes:
$format = "%H:%M:%S";
# Output: 14:30:45
$format = "%I:%M:%S %p";
# Output: 02:30:45 PM
%H is 24-hour (0-23), %I is 12-hour (1-12).
Questions about text counters
Questions about countdown timers
Browse all script FAQs