# Unix Timestamp (milliseconds)

Key: `datetime.epoch.unix_milliseconds`

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

Page: <https://meridian.online/docs/projects/finetype/types/datetime/epoch/unix_milliseconds>

Samples: `1705312200000`, `1577836799999`

## 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]](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html) Wikipedia records that the earliest versions of Unix time had a 32-bit integer incrementing at a rate of 60 Hz.[[2]](https://en.wikipedia.org/wiki/Unix_time) According to Wikipedia, the current epoch of 1 January 1970 00:00:00 UTC was selected arbitrarily by Unix engineers.[[2]](https://en.wikipedia.org/wiki/Unix_time) In Unix time, every day contains exactly 86400 seconds.[[2]](https://en.wikipedia.org/wiki/Unix_time)

An ECMAScript time value represents an instant in time to millisecond precision.[[3]](https://tc39.es/ecma262/multipage/numbers-and-dates.html) ECMAScript time values do not account for UTC leap seconds.[[3]](https://tc39.es/ecma262/multipage/numbers-and-dates.html) 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]](https://tc39.es/ecma262/multipage/numbers-and-dates.html) Java's System.currentTimeMillis() returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.[[4]](https://docs.oracle.com/javase/8/docs/api/java/lang/System.html) 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]](https://docs.oracle.com/javase/8/docs/api/java/lang/System.html)

### Use

JavaScript's Date.now() returns the number of milliseconds elapsed since the epoch.[[5]](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now) MDN notes that the precision of Date.now() may be reduced, depending on browser settings, to protect against timing attacks and fingerprinting.[[5]](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now) Elasticsearch stores dates internally as a long number representing milliseconds since the epoch.[[6]](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/date) When no format is set on a date field, Elasticsearch uses strict\_date\_optional\_time\|\|epoch\_millis.[[6]](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/date) 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]](https://www.rfc-editor.org/rfc/rfc9562.html)

Python's time.time() returns the time in seconds since the epoch as a floating-point number.[[8]](https://docs.python.org/3/library/time.html) Python's datetime.fromtimestamp() takes a POSIX timestamp such as is returned by time.time().[[9]](https://docs.python.org/3/library/datetime.html) 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]](https://duckdb.org/docs/current/sql/functions/timestamp.html) DuckDB's documentation gives make\_timestamp\_ms(1667810584123) as returning 2022-11-07 08:43:04.123.[[10]](https://duckdb.org/docs/current/sql/functions/timestamp.html) DuckDB's epoch\_ms() returns the total number of milliseconds since the epoch for a timestamp.[[10]](https://duckdb.org/docs/current/sql/functions/timestamp.html) 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]](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/mapping-date-format)

### 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]](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-api-information)

## Sources

1. [Definitions](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html) — standard
2. [Unix time](https://en.wikipedia.org/wiki/Unix_time) — secondary source
3. [ECMAScript® 2027 Language Specification](https://tc39.es/ecma262/multipage/numbers-and-dates.html) — standard
4. [System (Java Platform SE 8)](https://docs.oracle.com/javase/8/docs/api/java/lang/System.html) — documentation
5. [Date.now() - JavaScript \| MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now) — documentation
6. [Date field type](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/date) — documentation
7. [RFC 9562: Universally Unique IDentifiers (UUIDs)](https://www.rfc-editor.org/rfc/rfc9562.html) — standard
8. [time — Time access and conversions](https://docs.python.org/3/library/time.html) — documentation
9. [datetime — Basic date and time types](https://docs.python.org/3/library/datetime.html) — documentation
10. [Timestamp Functions](https://duckdb.org/docs/current/sql/functions/timestamp.html) — documentation
11. [format](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/mapping-date-format) — documentation
12. [General REST API Information \| Binance Developer Docs](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-api-information) — organisation
