Unix Timestamps, Time Zones and Dates: The Bugs Every Developer Hits
Seconds vs milliseconds, date-only parsing, DST gaps, cron in the wrong zone, month arithmetic and 2038: the time bugs that ship most often, with fixes.
An instant and a wall-clock time are different things
Most date bugs come from mixing up two ideas. An instant is a single point on the global timeline, the same everywhere: a Unix timestamp is one. A wall-clock time is what a clock on a particular wall shows, such as '10:00 on 21 October', and it only identifies an instant once you also know the time zone and its rules on that date.
Keeping these two apart solves a surprising number of problems. The rest of this article goes through the bugs that appear most often in real code, with examples you can check in a browser console or with the tools linked along the way.
Seconds or milliseconds?
A Unix timestamp counts time since 1970-01-01T00:00:00Z. Unix tools, most databases and JWTs count in seconds. JavaScript's Date.now() and Java's System.currentTimeMillis() count in milliseconds. Python's time.time() returns seconds as a float. Mix them up and the date is wildly wrong but often still valid, so nothing throws an error.
The value 1700000000 read as seconds is 2023-11-14T22:13:20Z. Read as milliseconds, it is 1970-01-20T16:13:20Z. The opposite mistake, treating milliseconds as seconds, gives a date tens of thousands of years in the future, which some date libraries reject and others quietly accept.
A quick sanity check is the digit count. Timestamps in seconds have had 10 digits since 2001-09-09T01:46:40Z and will keep 10 digits until the year 2286. Millisecond timestamps for current dates have 13 digits. The Unix Timestamp Converter on this site uses a similar rule: values above 100,000,000,000 are treated as milliseconds, otherwise as seconds. That threshold is 1973 in milliseconds and the year 5138 in seconds, so it is unambiguous for any realistic modern date.
The date-only string trap
In JavaScript, new Date("2026-10-21") is parsed as midnight UTC, because the ISO date-only form is defined that way. But new Date("2026-10-21T00:00"), with a time and no offset, is parsed as midnight local time. In New York in October, the first displays as 20 October at 8:00 pm, a day earlier than the string suggests. Users west of UTC see birthdays, due dates and booking dates shift back by a day.
The fix is to decide what the value means. A calendar date with no time, such as a birthday, should stay a plain date string or be stored as separate year, month and day values, and never be converted through an instant. A specific moment should always carry an explicit offset or Z, for example 2026-10-21T09:30:00+05:30 or 2026-10-21T04:00:00Z.
ISO 8601 and offsets that are not time zones
ISO 8601 strings like 2026-10-21T09:30:00+05:30 are the safest format for exchanging timestamps: they sort correctly as text, they are unambiguous, and every mainstream language parses them. The offset in the string tells you the relationship to UTC at that instant. It does not tell you the time zone.
+05:30 could be India, which has no daylight saving time, or another region that happens to share the offset on that date. Offsets are also not always whole hours: Nepal is at +05:45. Abbreviations are worse: CST can mean US Central Standard Time or China Standard Time, and IST is used for India, Ireland and Israel. Store IANA zone names such as Asia/Kolkata, Europe/London or America/New_York, which carry the full history of rule changes.
Store instants in UTC, but store future local events with their zone
For things that have already happened, such as log entries, payments and created-at fields, store the UTC instant. For things scheduled in the future in local time, such as a 10:00 meeting in Berlin next July or a shop opening hour, store the local date and time plus the IANA zone, and work out the instant when you need it. Governments do change daylight saving rules, sometimes with little notice, and an instant computed today could be an hour off by the time the event arrives.
Daylight saving time: gaps and overlaps
On the day clocks spring forward, one hour of local time does not exist. On the day they fall back, one hour happens twice. Code that assumes every day has 24 hours, or that every local time maps to exactly one instant, breaks on those days. These are the 2026 transitions for a few zones, calculated from the time zone database built into Node.js:
| Zone | Clocks go forward | Clocks go back |
|---|---|---|
| America/New_York | 8 March 2026, 02:00 becomes 03:00 | 1 November 2026, 02:00 becomes 01:00 |
| Europe/London | 29 March 2026, 01:00 becomes 02:00 | 25 October 2026, 02:00 becomes 01:00 |
| Europe/Berlin | 29 March 2026, 02:00 becomes 03:00 | 25 October 2026, 03:00 becomes 02:00 |
| Australia/Sydney | 4 October 2026, 02:00 becomes 03:00 | 5 April 2026, 03:00 becomes 02:00 |
| Asia/Kolkata | No DST | No DST |
What DST does to everyday code
In New York, 02:30 on 8 March 2026 never happens. Ask JavaScript for new Date("2026-03-08T02:30") with the system zone set to America/New_York and you get 03:30 EDT: the engine shifts the missing time forward. 01:30 on 1 November 2026 happens twice, and JavaScript resolves it to the first occurrence, 01:30 EDT. Other languages and libraries make different choices, and some throw an error instead, so test both edge cases explicitly.
Adding 24 hours is not the same as adding one day. In New York, noon on 7 March 2026 plus 24 hours is 13:00 on 8 March, not noon. And dividing the difference between two local midnights by 86,400,000 milliseconds gives 1.958 days for 7 to 9 March, so code that uses Math.floor reports one day instead of two. Do calendar arithmetic with calendar functions, or round rather than truncate when converting a duration to whole days.
Transitions also change the gap between zones for a few days each year. The UK and EU move their clocks back on 25 October 2026 and the US on 1 November, so for that week London is 4 hours ahead of New York instead of the usual 5. India does not change its clocks, so it goes from 4 hours 30 minutes ahead of London to 5 hours 30 minutes ahead on 25 October. Meeting invitations that were created as 'same time every week' in one zone quietly move for people in another. The Time Zone Converter on this site is a quick way to check these cases. By default it shows the live time across a set of cities, and you can pick any date and time in any IANA zone to see the same instant elsewhere, with each zone's offset on that date. Try 10:00 in London on 27 October 2026 against the same time a week earlier and the New York column moves by an hour. It uses your browser's time zone database, so the offsets follow each zone's DST rules for the date you choose.
Cron schedules run in somebody's time zone
A crontab entry has no time zone of its own. Classic cron runs jobs in the server's local zone, and some implementations and hosted schedulers let you set a zone per job or default to UTC. A job written as 0 9 * * * means 09:00 in whichever zone the scheduler uses, and moving the job to a server in a different region can shift it by hours without any change to the expression.
If the scheduler uses a zone with daylight saving time, jobs set between 01:00 and 03:00 are at risk: depending on the implementation, a job in the skipped hour may run late or not at all, and a job in the repeated hour may run twice. The safest options are to run schedulers in UTC and convert, or to avoid the transition window for jobs that must run exactly once.
One more classic: in standard cron, if both day-of-month and day-of-week are restricted, the job runs when either matches. 0 0 13 * 5 runs at midnight on every 13th of the month and also every Friday, not only on Friday the 13th. The Cron Expression Parser describes all five fields in plain English and lists the next five run times in your browser's local time zone, which makes this kind of mistake easy to spot: paste 0 0 13 * 5 and the upcoming runs include ordinary Fridays. Its preview follows the standard OR rule and the local clock, but your production scheduler may run in a different zone, so always confirm how your specific scheduler treats time zones.
Month and leap-year arithmetic
'One month later' is not a fixed duration. In JavaScript, taking 31 January 2026 and calling setMonth(1) gives 3 March 2026: there is no 31 February, so the extra days overflow into March. Many date libraries clamp to the last valid day instead and return 28 February. Neither is wrong, but billing dates, subscription renewals and EMI due dates need a deliberate rule, written down and tested.
Leap years follow three rules: divisible by 4, except years divisible by 100, except years divisible by 400. So 2000 and 2028 are leap years, while 1900, 2026 and 2100 are not. A birthday on 29 February 2028 plus one year in JavaScript becomes 1 March 2029, while some systems use 28 February. Legal age rules for leap-day birthdays vary by jurisdiction, so systems that check age for eligibility should follow the applicable rule rather than whatever the library does.
The Date Difference Calculator counts the days, weeks, and months plus days between two calendar dates, and adds or subtracts any number of days from a date. It does this on plain calendar dates in UTC, so a DST change in your local zone cannot turn a two-day gap into 1.958 days. The Age & Birthday Calculator gives an age in years, months and days by counting whole months from the birth date and then the leftover days, clamping to the end of a short month in the way many libraries do (31 January plus one month is 28 February there, not 3 March). Both are handy for checking what your own code should produce for a given pair of dates, and for seeing that the clamping rule and JavaScript's overflow rule give different answers.
The 2038 problem is closer than it looks
Systems that store Unix time as a signed 32-bit integer can count up to 2,147,483,647 seconds, which is 2038-01-19T03:14:07Z. One second later the value overflows and wraps to -2,147,483,648, which those systems read as 1901-12-13T20:45:52Z.
Most modern operating systems and languages use 64-bit time, but the limit survives in older embedded devices, 32-bit binaries, file formats, and database columns. MySQL's TIMESTAMP type, for example, has a documented upper limit of 2038-01-19 03:14:07 UTC, while its DATETIME type does not have this limit. In 2026 this is no longer a distant concern: a 15-year loan schedule, a long-lived certificate or an insurance policy created today already has dates past 2038. If your system stores any future date, test it with values beyond that point.
Quick reference
| Value | Meaning |
|---|---|
| 0 | 1970-01-01T00:00:00Z, the Unix epoch |
| 1000000000 | 2001-09-09T01:46:40Z, first 10-digit timestamp in seconds |
| 1792540800 | 2026-10-21T00:00:00Z |
| 2147483647 | 2038-01-19T03:14:07Z, the signed 32-bit limit |
| 10000000000 | 2286-11-20T17:46:40Z, first 11-digit timestamp in seconds |
A checklist for time-handling code
- Name every variable with its unit: createdAtMs, expiresAtSec.
- Store past events as UTC instants; store future local events as local time plus an IANA zone.
- Never parse date-only strings into instants when you mean a calendar date.
- Exchange timestamps as ISO 8601 with an explicit offset or Z.
- Use IANA zone names, never abbreviations like IST or CST.
- Test the spring-forward and fall-back days for every zone you support.
- Run schedulers in UTC, or keep critical jobs out of the 01:00 to 03:00 window.
- Write down your month-end and leap-day rules and test 31 January and 29 February.
- Check every storage layer for 32-bit time limits before dates past 2038 arrive in your data.
Frequently asked questions
How can I tell whether a timestamp is in seconds or milliseconds?
Count the digits. For current dates, seconds have 10 digits and milliseconds have 13. A value like 1700000000 is seconds; 1700000000000 is milliseconds. The Unix Timestamp Converter detects this automatically.
Why does my date show the day before in some time zones?
A date-only string such as 2026-10-21 is often parsed as midnight UTC. Displayed in a zone behind UTC, that instant falls on the previous evening. Keep calendar dates as dates rather than converting them to instants.
Should I store dates in UTC?
Store past events as UTC instants. For future events defined in local time, such as a meeting at 10:00 in Berlin, store the local time and the IANA time zone, because daylight saving rules can change before the event.
What exactly happens in 2038?
A signed 32-bit count of seconds since 1970 reaches its maximum at 2038-01-19T03:14:07Z and then wraps to a date in December 1901. Systems using 64-bit time are not affected, but 32-bit fields still exist in older software, devices and some database column types.
Which time zone does cron use?
Classic cron uses the server's local time zone. Some implementations and cloud schedulers let you set a zone per job or use UTC by default. Check your scheduler's documentation, and avoid scheduling critical jobs during daylight saving transitions.
Why is 31 January plus one month equal to 3 March in JavaScript?
Setting the month to February on a date with day 31 creates 31 February, which does not exist, so JavaScript rolls the extra days into March. Other libraries clamp to the last day of February. Choose a rule deliberately for billing or due dates.