Skip to content

Clock

Clock shows a Date object in any given format.

Options

ts
type ClockProps = {
    /**
     * Specify a date used to start the display on the clock.
     */
    date?: Date;
    /**
     * A format string for how the date is displayed.
     */
    format?: string;
    /**
     * A formatter to display the date in the given format.
     */
    formatter?: UseDateFormats | UseDateFormatsOptions;
};

Available Formats

For a full overview of Date Formatting refer to the reference.

FormatDescriptionOutputs
QThe quarter year (1-4)1
YYYY4 digit year2024
YY2 digit year24
M1 digit month1
MM2 digit month01
MMMAbbreviated monthJan
MMMMThe full monthJanuary
D1 digit day of the month1
DD2 digit day of the month01
DDDAbbreviated day of the weekMon
DDDDFull day of the weekMonday
H1 digit hour (1-24)1
HH2 digit hour (01-24)01
h1 digit hour (1-12)1
hh2 digit hour (01-12)01
m1 digit minute1
mm2 digit minute01
s1 digit second1
ss2 digit second01
v1 digit millisecond1
vv2 digit millisecond01
vvv1 digit millisecond001
vvvv2 digit millisecond0001
A"AM" or "PM"AM
a"am" or "pm"am

Basic Example

This example uses the default values. It starts on the current time and is formatted with [hh]:[mm]:[ss][A].

ts
import { clock, css, flipClock, theme } from 'flipclock';

const parent = document.querySelector('#clock')!;

flipClock({
    parent,
    face: clock(),
    theme: theme({
        dividers: ':',
        css: css({
            fontSize: '3rem'
        })
    })
});

24-Hour Clock

Like real life, a clock is not always showing the current time. This example shows a 24-hour clock that starts on a specific date in the past.

ts
import { clock, css, flipClock, theme } from 'flipclock';

const parent = document.querySelector('#clock')!;

flipClock({
    parent,
    face: clock({
        date: new Date('2025-01-01 18:30'),
        format: '[HH]:[mm]:[ss]'
    }),
    theme: theme({
        dividers: ':',
        css: css({
            fontSize: '3rem'
        })
    })
});

Digitizing

Digitizing in the process by which individual characters are display on a clock. Consider the following format: [hh]:[mm]:[ss][A]. The letters are date formatting flags. The brackets denote groups. Groups are not required, but allow for more control over the markup and styling of the clock.

Released under the MIT License.