Quick revision
The short answer
The standard is one rule per meaning. A moment travels as an ISO-8601 string in UTC, or with an explicit offset, in APIs and events, and is stored in timestamp with time zone or in UTC by a documented convention per database. A future user-facing time travels as a local date-time plus an IANA zone ID, and a local date-time without a zone is never used for a moment. A shared library with serialisers and validation, plus contract tests and schema rules that reject zoneless timestamps, keeps teams on the standard.
What to remember
In this answer, we replaced four formats with one rule per meaning. Moments travel as ISO-8601 in UTC, or with an explicit offset, and are stored in timestamptz or UTC by a documented per-database rule. Future user-facing times travel and are stored as a local date-time plus an IANA zone ID, and a zoneless local date-time is never accepted as a moment. A shared library makes the standard the easy path, schemas and contract tests enforce it at the boundaries, and new fields alongside old ones let us migrate without breaking consumers.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The standard is one rule per meaning. A moment travels as an ISO-8601 string in UTC, or with an explicit offset, in APIs and events, and is stored in timestamp with time zone or in UTC by a documented convention per database. A future user-facing time travels as a local date-time plus an IANA zone ID, and a local date-time without a zone is never used for a moment. A shared library with serialisers and validation, plus contract tests and schema rules that reject zoneless timestamps, keeps teams on the standard.
Why this question is asked
When timestamps travel in four formats, every boundary between services becomes a small translation job, and some translations are wrong. Epoch milliseconds get read as seconds, local strings get read in the wrong zone, and a database type quietly converts through a session setting. Interviewers ask senior engineers this to see whether they can set a standard that is simple enough to follow and strict enough to enforce. In this answer, we will look at why the four formats cause trouble, set rules for moments, for future local times, and for storage, and then make the standard stick with a shared library, contract tests and a migration plan.
1Why Four Formats Cause Bugs
Each of the formats in the question has its own trap. Epoch millis, such as 1741593600000, are compact but unreadable, and nothing in the value says whether it is seconds or milliseconds, so a consumer that guesses wrong is off by a factor of a thousand. ISO strings with offsets, such as 2025-03-10T09:00+01:00, are fine. Local strings with no zone, such as 2025-03-10T09:00, cannot be placed on the timeline at all; every consumer must guess the zone. Database-specific types convert through session settings that differ between connections.
The fix is not to pick one format for everything. A delivery that happened and a dentist appointment next spring are different kinds of values, and pretending otherwise causes a second class of bugs. So the standard starts by naming the meanings, then picks one representation for each.
2Rule 1: Moments Travel as ISO-8601 in UTC
A moment is something that happened, or will happen, at one point on the global timeline: an order was placed, a token expires. In APIs and events, moments travel as ISO-8601 strings, normally in UTC with the Z suffix. An explicit offset is also accepted, because it is equally unambiguous; in Java the field is an Instant or an OffsetDateTime.
We prefer strings over epoch numbers because they are readable in logs and support tickets, they make the unit obvious, and every language parses them. Notice that 'never send a local date-time without a zone for a moment' follows directly from this rule: a moment without a zone is simply not a valid value.
3Rule 2: Future Local Times Carry a Zone ID
Some values are meant in a user's local time: 'the meeting is at 09:00 Paris time on 12 May next year'. If we convert that to an instant today and store only the instant, and France changes its daylight saving rules before then, the stored instant points to 10:00 or 08:00 local time. The user meant 09:00, so the instant alone loses their intent.
So user-facing future times travel as a local date-time plus an IANA zone ID, such as Europe/Paris. Not an abbreviation like CET and not a fixed offset like +02:00, since neither knows the rules. The consumer computes the instant when it needs one, using the zone rules current at that time. We may also include the computed instant for convenience, but the local time and the zone are the truth.
| Meaning | In APIs and events | In storage |
|---|---|---|
| Moment (happened or will happen) | ISO-8601 UTC, e.g. 2025-03-10T08:00:00Z | timestamptz, or UTC by documented rule |
| Future local time for a user | local date-time + IANA zone ID | two columns: local timestamp + zone text |
| Calendar date | ISO date, e.g. 2025-03-10 | date |
| Moment as local string, no zone | Rejected | Rejected |
4Rule 3: Storage, Documented Per Database
In storage, moments go into a column that stores a moment: timestamp with time zone in PostgreSQL. Where a database has no good equivalent, or the column is a legacy DATETIME, the rule is that the value is UTC by convention, and the convention is written down per database in the standard, with the exact column type and driver settings. A future local time is stored as two columns, the local date-time and the zone ID, so a rule change can be applied later.
Notice that the standard is written per database because each has its own traps, such as session time zone conversion in MySQL's TIMESTAMP. Teams should not have to rediscover those traps one at a time.
5Making It Stick: A Shared Library and Contract Tests
A standard that each team implements by hand drifts within a year. So the platform team provides a shared library, typically a Spring Boot starter and a small module for event serialisation, that configures Jackson and the messaging serialisers to write instants as ISO-8601 UTC, rejects zoneless strings on input for moment fields, and offers a ZonedLocalTime value type for future local times. Teams get the standard by adding a dependency, not by reading a wiki.
Then we enforce it at the boundaries. API schemas declare moment fields as string with format date-time, which requires an offset. Event schemas use the registry's timestamp types. A contract test in each producer's build checks that sample payloads validate against the schema, and a lint rule in schema review flags any timestamp field without a zone. The reason we check at the boundary is that a wrong format inside one service is a local bug, while a wrong format on the wire becomes every consumer's bug.
6Migrating the Existing Mess
We do not break the existing consumers. For each API or event that uses an old format, the producer adds a new field in the standard format next to the old one, for example placedAt beside placed_at_millis, and documents the old field as deprecated. Consumers switch at their own pace, the producer watches which consumers still read the old field, and removes it after a published deadline. New fields and new topics must follow the standard from the start, which the schema rules enforce.
- Inventory fields and their real meaningmoment, future local time or date
- Add standard field next to the old one
placedAtbeside placed_at_millis - Consumers switchtracked per consumer
- Any consumer left on the old field?YesRemind, help, extend onceNoRemove the old field
4 steps in order. Play them, or step through them one at a time.
7Follow-up questions
Why not use epoch milliseconds everywhere? They are compact and unambiguous.
They are unambiguous only if every consumer knows the unit. Seconds and milliseconds look similar at a glance, and nothing in the value says which it is. They are also unreadable in logs and support tickets, which slows every investigation. ISO-8601 strings are self-describing and only slightly larger; where size really matters, as in a binary event format, we use the schema's typed timestamp, which records the unit in the schema.
Should APIs return times in the user's local zone?
The API should return the moment in UTC, plus the user's zone if the client needs it. Formatting into local time for display is the client's job, at the edge. Returning local strings from APIs pushes zone guessing into every consumer.
How do you handle a consumer that cannot parse offsets?
We fix the consumer rather than weaken the standard, but we give it time: the old field stays during the deprecation period. In practice almost every modern library parses ISO-8601 with offsets, so this is usually a matter of updating a parser.
8Conclusion
In this answer, we replaced four formats with one rule per meaning. Moments travel as ISO-8601 in UTC, or with an explicit offset, and are stored in timestamptz or UTC by a documented per-database rule. Future user-facing times travel and are stored as a local date-time plus an IANA zone ID, and a zoneless local date-time is never accepted as a moment. A shared library makes the standard the easy path, schemas and contract tests enforce it at the boundaries, and new fields alongside old ones let us migrate without breaking consumers.
Open with
I would set one representation per meaning, because the bugs come from treating different kinds of time as one thing. For moments, which is most fields, like created or expires, APIs and events use ISO-8601 strings in UTC, with an explicit offset also accepted because it is equally unambiguous; in Java that is Instant or OffsetDateTime.
Then, if they want more
For future times that a user means in their local time, like a meeting at 9 in Paris next spring, we send a local date-time plus an IANA zone ID, because if the zone's rules change, an instant computed today would be wrong. A local date-time with no zone is never valid for a moment.
In storage, moments go into timestamptz in PostgreSQL, or UTC by convention where the database lacks a proper type, and that is documented per database. Future local times are two columns, the local value and the zone.
To make it stick, the platform team ships a shared library with the serialisers and validation, schemas declare format date-time, and contract tests reject zoneless timestamps. For existing fields, producers add the new field beside the old one, consumers migrate, and the old field is removed after a deadline.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Across many services, timestamps travel as epoch millis, ISO strings with offsets, local...": https://scrivio-interview-library.netlify.app/java/date-and-time/f7a918448b/