Text Clock FAQ

Frequently asked questions about the Text Clock script.

Q1: How do I change the time format?

Short Answer:

Edit the format string in the script.

Long Answer:

The Text Clock uses Perl's strftime format codes. Find the format string in the script and customize it:

Common Format Codes:
%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)
Examples:
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

Q2: The clock shows the wrong timezone.

Short Answer:

Set the TZ environment variable.

Long Answer:

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

Q3: Can I make the clock update automatically?

Short Answer:

Yes, use meta refresh or JavaScript.

Long Answer:

The CGI script shows the time when executed. To update automatically, you have several options:

Method 1: Meta Refresh (Simple)
<meta http-equiv="refresh" content="1">

Refreshes entire page every second. Simple but causes flicker.

Method 2: JavaScript (Better)

Use JavaScript to update the clock client-side without reloading.

More efficient and no flicker.

Method 3: AJAX (Best)

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);

Q4: How do I switch to 12-hour format?

Short Answer:

Use %I instead of %H and add %p for AM/PM.

Long Answer:

Change your format string to use 12-hour time codes:

24-hour Format:
$format = "%H:%M:%S";
# Output: 14:30:45
12-hour Format:
$format = "%I:%M:%S %p";
# Output: 02:30:45 PM

Related FAQs

Text Counter FAQ

Questions about text counters

Countdown FAQ

Questions about countdown timers

All FAQs

Browse all script FAQs