Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

time2date

Convert a Unix time_t (optionally milliseconds) to ASCII date/time, and vice-versa, in UTC, local and a given time zone.

Usage

time2date [TIME_T]            # no arg => current time; also accepts a date string
OptionPurpose
[TIME_T]Epoch seconds as a JSON integer (1792573200, 0, -5), or a date with a T (2026-10-01T10:00:00Z). Optional positional, now when absent
--TZ / -zTime zone for the conversion
--miliseconds / -mTreat the input as milliseconds

Prints the timestamp (and its hex form) plus UTC + local (and named-TZ) ISO-8601 strings and yday. A time no calendar holds, in UTC or in the local zone, prints “timestamp too big” with exit code -1: up to 7.29.3 time2date 67768036191676799 in a zone east of UTC crashed.

time2date -z Europe/Madrid 1792573200
# gmtime of 1792573200 (...): UTC 2026-10-21T09:00:00+0000, Europe/Madrid 2026-10-21T11:00:00+0200, LOCAL ..., yday 293
time2date 2026-10-01T10:00:00Z
# gmtime of 1790848800 (...): UTC 2026-10-01T10:00:00+0000, LOCAL ..., yday 273

A refusal prints no answer and exits with code -1 (255 in the shell):

A time before the epoch is a negative number, written after -- so that it is not taken as an option. With -m, it is divided as a signed number (up to 7.30.14 as an unsigned one):

time2date -- -5           # UTC 1969-12-31T23:59:55+0000
time2date -m -- -5000     # the same second

See also