Examples
- 0 is 1 January 1970, 00:00:00 UTC.
- 1700000000 is 14 November 2023, 22:13:20 UTC.
Unix timestamp digits: 10, 13, 16 or 19
Count the digits to find the unit. The values below all describe the same moment, 14 November 2023 at 22:13:20 UTC.
| Digits | Unit | Example | To get seconds |
|---|---|---|---|
| 10 | Seconds | 1700000000 | Use as it is |
| 13 | Milliseconds | 1700000000000 | Divide by 1,000 |
| 16 | Microseconds | 1700000000000000 | Divide by 1,000,000 |
| 19 | Nanoseconds | 1700000000000000000 | Divide by 1,000,000,000 |
This applies to current dates. Much older or much later moments have a different number of digits.
Unix timestamp in nanoseconds
- Python:
time.time_ns() - Go:
time.Now().UnixNano() - Linux terminal:
date +%s%N(GNU date) - JavaScript:
BigInt(Date.now()) * 1000000n, which has millisecond precision only
A nanosecond timestamp is larger than JavaScript's biggest safe integer, so keep it as a BigInt or a string. The unit describes the format, and the real precision depends on the system clock.
Useful reference timestamps
| Moment | Unix timestamp (seconds) | Date and time |
|---|---|---|
| Unix epoch | 0 | 1970-01-01 00:00:00 UTC |
| 1 billion seconds | 1000000000 | 2001-09-09 01:46:40 UTC |
| Start of 2020 | 1577836800 | 2020-01-01 00:00:00 UTC |
| Start of 2024 | 1704067200 | 2024-01-01 00:00:00 UTC |
| 1.7 billion seconds | 1700000000 | 2023-11-14 22:13:20 UTC |
| Start of 2025 | 1735689600 | 2025-01-01 00:00:00 UTC |
| Start of 2026 | 1767225600 | 2026-01-01 00:00:00 UTC |
| Start of 2027 | 1798761600 | 2027-01-01 00:00:00 UTC |
| 2 billion seconds | 2000000000 | 2033-05-18 03:33:20 UTC |
| 32-bit limit (2038 problem) | 2147483647 | 2038-01-19 03:14:07 UTC |
Seconds in common time periods
| Period | Seconds |
|---|---|
| 1 minute | 60 |
| 1 hour | 3,600 |
| 1 day | 86,400 |
| 1 week | 604,800 |
| 30 days | 2,592,000 |
| 1 year (365 days) | 31,536,000 |
How to get the current Unix timestamp
- JavaScript:
Math.floor(Date.now() / 1000) - Python:
int(time.time())afterimport time - PHP:
time() - MySQL:
SELECT UNIX_TIMESTAMP(); - PostgreSQL:
SELECT EXTRACT(EPOCH FROM NOW()); - Linux or macOS terminal:
date +%s
Convert a Unix timestamp to a date in code
- JavaScript:
new Date(ts * 1000).toISOString() - Python:
datetime.fromtimestamp(ts, tz=timezone.utc) - PHP:
date('c', $ts) - MySQL:
SELECT FROM_UNIXTIME(ts); - PostgreSQL:
SELECT to_timestamp(ts); - Linux terminal:
date -d @ts(on macOS usedate -r ts)
More ways to get the current epoch time
- Java:
Instant.now().getEpochSecond() - Go:
time.Now().Unix() - C#:
DateTimeOffset.UtcNow.ToUnixTimeSeconds() - Ruby:
Time.now.to_i - JavaScript in milliseconds:
Date.now()
Epoch time, POSIX time and Unix time
These names all mean the same thing: a count of seconds since the epoch, 1 January 1970 UTC. POSIX time is the name used in the standard that defines it.
Seconds or milliseconds?
Traditional Unix time counts seconds and has 10 digits for dates today. JavaScript and many APIs use milliseconds, which have 13 digits. If a converted date lands in 1970 or in the far future, you probably mixed up the two.
Converting by hand
Divide the timestamp by 86,400 to get days since the epoch, since a day has 86,400 seconds. Then add that many days to 1 January 1970. Software does this for you and accounts for leap years.
Why developers use Unix time
- It is compact and easy to compare and sort.
- It avoids time-zone and daylight-saving confusion because it is always UTC.
- It is supported by virtually every programming language and database.
Best practices
- Store and transmit time in UTC, and convert to local time only for display.
- Be explicit about seconds versus milliseconds in field names.
- Prefer 64-bit integers for timestamps.
- Use ISO 8601 text, such as 2023-11-14T22:13:20Z, when humans need to read the data.
The year 2038 problem
Systems that store Unix time in a signed 32-bit integer will overflow at 2147483647, which is 19 January 2038 at 03:14:07 UTC. Most modern systems use 64-bit values and are not affected, but old embedded systems may be.
FAQ
Does Unix time count leap seconds?
No. Unix time ignores leap seconds, treating every day as exactly 86,400 seconds.
What is the current Unix timestamp?
It is the number of seconds since 1 January 1970 UTC right now. The Unix timestamp converter shows it live and updates every second.
Can a timestamp be negative?
Yes. Negative values represent moments before 1 January 1970.
Convert any timestamp with the free converter below.