TextClock Script: Modern Alternatives

TextClock displayed server time and date. Today, JavaScript handles time display client-side with timezone awareness and real-time updates.

Date & Time

JavaScript Date Libraries

Day.js

Fast 2KB alternative to Moment.js. Same modern API, immutable, chainable. Plugins for timezones, relative time, and formatting.

Free MIT License ~2KB Tree-shakable
date-fns

Modern JavaScript date utility library. Over 200 functions, modular design, TypeScript support. Tree-shakable for minimal bundle size.

Free MIT License 200+ functions
Luxon

Modern date-time library by Moment.js team. Built-in timezone support using Intl API, immutable, good documentation.

Free MIT License Timezone support
Native JavaScript Date API

Modern browsers have powerful built-in date formatting with Intl.DateTimeFormat. No library needed for basic use cases.

Built-in No dependencies Browser native

World Clock Services

TimeAndDate.com Widgets

Free embeddable world clocks and countdown timers. Multiple styles, customizable colors, any timezone supported.

Free Embed code World timezones
World Time API

Simple JSON API for current time in any timezone. No authentication required, free for non-commercial use.

Free JSON API No auth

Code Examples

Native JavaScript - Live Clock
function updateClock() {
  const now = new Date();
  const options = {
    weekday: 'long',
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  };
  document.getElementById('clock').textContent =
    now.toLocaleDateString('en-US', options);
}
setInterval(updateClock, 1000);
updateClock();
Day.js - Formatted Time
import dayjs from 'dayjs';

// Format: Monday, December 16, 2024 3:45 PM
const formatted = dayjs().format('dddd, MMMM D, YYYY h:mm A');

// Relative time: "2 hours ago"
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
const relative = dayjs('2024-12-16').fromNow();

Feature Comparison

Feature TextClock (CGI) JavaScript
Time sourceServerClient (local)
Real-time updateNoYes
User's timezoneNoAutomatic
Custom formatsLimitedExtensive
Relative timeNo"2 hours ago"
Multiple timezonesComplexEasy
Server loadEach requestNone

Recommendation

Minimal: Native Intl.DateTimeFormat

Lightweight: Day.js (~2KB)

Full-featured: date-fns

Timezone heavy: Luxon

NPM Install

npm install dayjs
npm install date-fns
npm install luxon
All Examples TextClock Overview