What Unix time counts
Unix time is the number of seconds since 00:00:00 UTC on 1 January 1970, not counting leap seconds. It has no time zone. The same number means the same instant everywhere, and a time zone is only applied when the number is shown as a date.
Seconds or milliseconds?
Different systems store different precision. The page decides by the size of the number.
| Digits (for current dates) | Unit | Where you see it |
|---|---|---|
| 10 | Seconds | Unix tools, JWT exp and iat, PHP, Python time.time() (as a float) |
| 13 | Milliseconds | JavaScript Date.now(), Java System.currentTimeMillis() |
| 16 | Microseconds | PostgreSQL internals, some logging systems |
| 19 | Nanoseconds | Go UnixNano(), some tracing formats |
A date in 1970 that should be recent means a seconds value was read as milliseconds. A date tens of thousands of years ahead means the opposite.
Getting the current timestamp in code
JavaScript Math.floor(Date.now() / 1000)
Python int(time.time())
Go time.Now().Unix()
Java Instant.now().getEpochSecond()
PHP time()
Bash date +%s
SQL SELECT EXTRACT(EPOCH FROM now()); -- PostgreSQL
SELECT UNIX_TIMESTAMP(); -- MySQLQuestions
What is the year 2038 problem?
A signed 32-bit integer can count seconds only up to 2,147,483,647, which is 03:14:07 UTC on 19 January 2038. Systems that still store time in 32 bits will overflow at that moment. 64-bit timestamps do not have the problem.
Why is my converted time off by some hours?
The timestamp is fine and the time zone is not what you expected. Compare the UTC row with the local row.
Can a timestamp be negative?
Yes. Negative values are dates before 1970.