MeridianMERIDIAN

Unix Timestamp (milliseconds)

datetime.epoch.unix_millisecondswas datetime.unix_epoch_in_milliseconds in v1

Milliseconds since epoch. Common in JavaScript (Date.now()), Java (System.currentTimeMillis()), and many APIs.

Worked samples

DuckDB 1.5.5 · finetype 0.6.64

ValueAs TIMESTAMP
17053122000002024-01-15 09:50:00+00
15778367999992019-12-31 23:59:59.999+00

Shape

Pattern
^\d{13}$
ValueLengthShape
170531220000013matches
157783679999913matches
17053122000012rejected: one character short

Background

Origin

The Open Group Base Specifications define the Epoch as the time zero hours, zero minutes, zero seconds, on January 1, 1970 Coordinated Universal Time (UTC).[1] Wikipedia records that the earliest versions of Unix time had a 32-bit integer incrementing at a rate of 60 Hz.[2] According to Wikipedia, the current epoch of 1 January 1970 00:00:00 UTC was selected arbitrarily by Unix engineers.[2] In Unix time, every day contains exactly 86400 seconds.[2]

An ECMAScript time value represents an instant in time to millisecond precision.[3] ECMAScript time values do not account for UTC leap seconds.[3] The ECMAScript specification gives time values a supported range of exactly -100,000,000 days to 100,000,000 days relative to midnight at the beginning of 1 January 1970 UTC.[3] Java's System.currentTimeMillis() returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.[4] Java's documentation notes that while the unit of currentTimeMillis() is a millisecond, the granularity of the value depends on the underlying operating system and may be larger.[4]

Use

JavaScript's Date.now() returns the number of milliseconds elapsed since the epoch.[5] MDN notes that the precision of Date.now() may be reduced, depending on browser settings, to protect against timing attacks and fingerprinting.[5] Elasticsearch stores dates internally as a long number representing milliseconds since the epoch.[6] When no format is set on a date field, Elasticsearch uses strict_date_optional_time||epoch_millis.[6] RFC 9562 defines the unix_ts_ms field of a UUIDv7 as a 48-bit big-endian unsigned number of the Unix Epoch timestamp in milliseconds.[7]

Python's time.time() returns the time in seconds since the epoch as a floating-point number.[8] Python's datetime.fromtimestamp() takes a POSIX timestamp such as is returned by time.time().[9] Before converting a column of epoch numbers, confirm from the source's documentation whether they count seconds, milliseconds or microseconds. (Meridian's view) DuckDB's make_timestamp_ms() converts milliseconds since the epoch to a timestamp.[10] DuckDB's documentation gives make_timestamp_ms(1667810584123) as returning 2022-11-07 08:43:04.123.[10] DuckDB's epoch_ms() returns the total number of milliseconds since the epoch for a timestamp.[10] Convert the number as UTC first, and apply any local time zone afterwards. (Meridian's view) Elasticsearch's format reference warns that lenient date_optional_time parsing can lead to unexpected results when paired with a numeric format such as epoch_millis.[11]

Where you'll meet it

Binance's spot REST API documentation states that all time and timestamp related fields in its JSON responses are in milliseconds by default.[12]

Detection notes

v1 name: datetime.unix_epoch_in_milliseconds

Use it

CLI · DuckDB
$ finetype infer -i "1705312200000" --mode column
→ datetime.epoch.unix_milliseconds

SELECT ft_infer('1705312200000');
-- → 'datetime.epoch.unix_milliseconds'
Cast expression
to_timestamp({col}::BIGINT / 1000)

Schema

https://meridian.online/schemas/datetime.epoch.unix_milliseconds · Frictionless type integer

finetype taxonomy datetime.epoch.unix_milliseconds -o json-schema

Aliases

unix_epoch_in_milliseconds

Type Registry