Unix timestamps are the backbone of time handling in computing. Here is everything you need to know about converting between timestamps and dates.
What is a Unix Timestamp?
A Unix timestamp counts the number of seconds since January 1, 1970 00:00:00 UTC (the Unix epoch). Right now, it is around 1,772,000,000.
JavaScript
// Current timestamp (seconds)
Math.floor(Date.now() / 1000)
// Timestamp to Date
new Date(1672531200 * 1000) // 2023-01-01
// Date to Timestamp
new Date('2023-01-01').getTime() / 1000
Python
import time, datetime
# Current timestamp
int(time.time())
# Timestamp to datetime
datetime.datetime.fromtimestamp(1672531200)
# Datetime to timestamp
int(datetime.datetime(2023, 1, 1).timestamp())
Milliseconds vs Seconds
| Source | Format | Example |
|---|---|---|
| Unix/Python | Seconds | 1672531200 |
| JavaScript | Milliseconds | 1672531200000 |
| Java | Milliseconds | 1672531200000L |
Common Gotchas
- Timezone confusion - timestamps are always UTC
- Seconds vs milliseconds - JavaScript uses ms, most others use seconds
- Y2K38 problem - 32-bit timestamps overflow on Jan 19, 2038
- Daylight saving time - UTC timestamps avoid DST issues entirely
Try It Online
Convert timestamps with DevToolBox Timestamp Converter - supports seconds, milliseconds, multiple date formats.
What timestamp bugs have you encountered? Share below!
Top comments (0)