Unix Timestamps and Time Zones Explained
Dates and times are a common source of bugs because the same moment is written differently in different places. Two ideas solve most of the confusion: store time in a universal form, and convert only when you display it.
What is a Unix timestamp?
A Unix timestamp is the number of seconds since 1 January 1970 at 00:00 UTC (the "epoch"). For example, 1700000000 is a specific moment in November 2023. Because it is one number with no time zone attached, it is easy to store, sort and compare. Some systems use milliseconds (a number about a thousand times larger); if a converted date lands in the year 50,000, that is the clue.
Converting
The Unix Timestamp Converter turns a timestamp into a readable date and back. Always check which time zone the result is shown in; UTC is the reference, and your local time may differ by hours.
Why use UTC internally
- No ambiguity: UTC has no daylight-saving changes.
- Easy arithmetic: the difference between two timestamps is just a subtraction.
- Convert to the user's time zone only at the last step, for display.
Planning across time zones
For meetings, the Time Zone Converter shows the matching time in each city. Remember that daylight-saving dates differ between countries, so two cities that normally differ by five hours can differ by four or six for a few weeks each year.
Date arithmetic and other conversions
- How many days between two dates: Date Difference.
- Age from a birth date: Age Calculator.
- Seconds, minutes, hours and days: Time Converter.
- Scheduling recurring jobs: see our guide to cron expressions.
Common mistakes
- Assuming a day is always 24 hours (it is not on daylight-saving change days).
- Storing local time without the zone, which makes it impossible to interpret later.
- Confusing seconds and milliseconds.
Frequently asked questions
What happens in the year 2038?
Systems that store the timestamp in a signed 32-bit integer will overflow in January 2038. Modern systems use 64-bit values, which last far beyond any practical need.
Why does my date appear one day off?
The time was probably converted between time zones, moving it across midnight. Always keep track of which zone a date is in.
Is UTC the same as GMT?
For everyday purposes they show the same time. UTC is the modern standard used in computing and does not change with daylight saving.
How should I store dates in a database?
Store the moment in UTC (a timestamp or an ISO 8601 string with a zone), and convert to the user's time zone when displaying it.
Key takeaways
- Store time in UTC; convert for display.
- Check whether a timestamp is in seconds or milliseconds.
- Daylight saving changes the offset between cities during the year.