How to handle time zones in your app — 5 steps so the date stops slipping

A time zone bug doesn't crash. It quietly shows the wrong date — and you hear about it from a user in another country a month later.
Good news: the fix isn't cleverness, it's discipline. Five steps, minutes each. Here they are in order, with code.
If UTC doesn't mean much to you yet, start with what UTC is. This piece is pure practice.
1. Give your column a zone, not just digits
The most common mistake happens at schema time. Postgres has two lookalike types, and the difference is huge:
created_at timestamp -- bare digits, the zone is silently dropped
created_at timestamptz -- a moment in time, converted to UTC
Take timestamptz. It converts incoming values to UTC and stores the moment, not "19:00 somewhere". It doesn't remember the original zone — and that's correct, a moment doesn't depend on one.
For a new table:
create table orders (
id bigserial primary key,
created_at timestamptz not null default now()
);
If the table already exists, that's a separate migration:
alter table orders
alter column created_at type timestamptz
using created_at at time zone 'UTC';
Note the using: you're stating explicitly how to read the old digits. Without that line the database assumes the server's zone — and your whole archive shifts.
2. Send ISO 8601 with a Z over the wire
Time should leave your API in exactly one format: 2026-08-20T21:30:00Z. The trailing Z means "already UTC".
res.json({ createdAt: order.createdAt.toISOString() })
// "2026-08-20T21:30:00.000Z"
Never send a pre-formatted string like "20/08/2026 21:30". It looks tidy and is useless: the client has no idea whose time that is, and nothing can recover it.
The rule is simple: formatting is last-mile work. While data is on the wire, it stays a moment.
3. Turn the moment into text only in the browser
Only the client knows where the person is sitting. So format there:
const fmt = new Intl.DateTimeFormat("en-GB", {
dateStyle: "short",
timeStyle: "short",
});
fmt.format(new Date("2026-08-20T21:30:00Z"));
// in Moscow -> "21/08/2026, 00:30"
// in Los Angeles -> "20/08/2026, 14:30"
No zone given means the system one is used. That's what you want in 90% of cases.
Nothing to install: Intl is built into browsers and Node. Date libraries are rarely needed here.
Right next door sits relative time, the thing people usually hand-roll:
new Intl.RelativeTimeFormat("en", { numeric: "auto" }).format(-5, "minute")
// "5 minutes ago"
It handles plurals and every language at once. You still compute the difference in minutes yourself — but you no longer pick the wording.
4. Let the user override the zone
The system zone is right almost always. Almost — because someone's travelling but plans meetings in home time.
First detect the current one and show it as the default:
new Intl.DateTimeFormat().resolvedOptions().timeZone
// "Europe/Moscow"
Save their choice in the profile as a zone name string, "Europe/Moscow", not an offset like "+3". An offset lives until the next clock change; a name is a rule that updates with the system.
Then just feed the saved value into timeZone:
new Intl.DateTimeFormat("en-GB", {
dateStyle: "short",
timeStyle: "short",
timeZone: user.timeZone,
}).format(date)
5. Test on zones a full day apart
Testing in your own zone proves nothing: everything lines up. You need the edges of the scale.
Take Kiritimati (UTC+14) and Niue (UTC−11) — exactly a day between them. The same instant:
TZ=Pacific/Kiritimati node -e 'console.log(new Date("2026-08-20T21:30:00Z").toLocaleString("en-GB"))'
# 21/08/2026, 11:30:00
TZ=Pacific/Niue node -e 'console.log(new Date("2026-08-20T21:30:00Z").toLocaleString("en-GB"))'
# 20/08/2026, 10:30:00
Different dates. If "today" is hardcoded anywhere in your UI, those two runs will disagree — and you find the bug yourself instead of hearing about it.
The browser tests the same way: in DevTools open the Sensors panel and override Location — the zone changes there too.
And while you're at it, remember scheduled jobs: server cron almost always runs on UTC. Your "report at 9am" lands at noon unless you do the maths.
What you end up with
After five steps you have an app where:
- the database holds moments, not guesses;
- the API sends unambiguous strings that survive a server move;
- every user sees their own local time without configuring anything;
- anyone who needs to can change their zone;
- date bugs get caught before release, with two terminal commands.
The thing to take away: a time is a moment; a date is already an opinion. Store moments and you sleep well.
FAQ
What if I'm on SQLite, which has no timestamptz?
SQLite has no date type at all — dates are stored as text or numbers. Same rule applies: write an ISO string with Z, or Unix seconds. What matters is picking one and never mixing formats in a single column.
Do I need a library like Day.js or Luxon?
For display, almost never — Intl covers it. A library pays off once arithmetic starts: "add a month", "start of week in the user's zone", recurring events. Then reach for Luxon, or the built-in Temporal if your runtime already ships it.
How do I store a meeting time that must not shift?
That's a special case: "every Tuesday at 19:00 local" isn't a moment, it's a rule. Store those as a pair — local time plus zone name. Compute the moment at display time, or the class moves an hour after the next clock change.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





