Quick revision
The short answer
I would agree one standard for the whole platform: points in time are Instant (or OffsetDateTime) written as ISO-8601 strings in UTC, and dates without a time are LocalDate. The standard ships through the shared starter and shared DTO types, so most services change by upgrading a dependency. Fields whose format or meaning changes are versioned or documented for the mobile clients, and contract tests on date formats keep every service on the standard afterwards.
What to remember
In this answer, we fixed wrong dates across 30 services by first auditing every date field and the zone behind it, then agreeing one standard: Instant or OffsetDateTime as ISO-8601 in UTC for points in time and LocalDate for dates without time. The shared starter and shared DTOs carry most of the change, stored local times are migrated with their recorded zone, changed fields are versioned or documented for mobile clients with a single coordinated plan, and contract tests on date formats keep every service on the standard.
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.
I would agree one standard for the whole platform: points in time are Instant (or OffsetDateTime) written as ISO-8601 strings in UTC, and dates without a time are LocalDate. The standard ships through the shared starter and shared DTO types, so most services change by upgrading a dependency. Fields whose format or meaning changes are versioned or documented for the mobile clients, and contract tests on date formats keep every service on the standard afterwards.
Why this question is asked
When thirty services each made their own choice about dates, mobile users see the consequences directly: an order placed at 23:30 shows up as the next day, a delivery date is one day early in another time zone, and a push notification says a coupon expired an hour before it did. The fix is not hard in any single service; the hard part is changing thirty services and several app versions in the wild without breaking anything on the way. Interviewers ask this scenario to see how we turn a technical rule into a coordinated change. In this answer, we will find out what is really wrong, define the standard, roll it out through shared code, handle the clients, and make sure it stays fixed.
1Finding Out What Is Really Wrong
Before changing anything, we sample real responses from each service and classify every date field. In a typical audit we find four patterns. Some services send LocalDateTime from LocalDateTime.now() on servers in different default zones, so the same moment appears as different strings. Some send epoch arrays because they replaced Boot's ObjectMapper. Some convert calendar dates, such as a delivery date, to midnight timestamps, which shift by a day in other zones. And a few already send correct UTC instants.
The audit also tells us what the stored data means. A LocalDateTime column filled by a Berlin server holds Berlin wall-clock time; the same column type in another service may hold UTC. We need that knowledge before migrating data, so we write it down per field.
| Pattern found | Services | Symptom on mobile |
|---|---|---|
LocalDateTime, server zone Berlin | 9 | times off by 1-2 hours outside Germany |
LocalDateTime, server zone UTC | 8 | times off by the user's offset |
Epoch arrays from own ObjectMapper | 4 | parse errors, fallback text |
| Calendar date as midnight timestamp | 5 | delivery date one day early in the Americas |
| Instant in UTC already | 4 | correct |
2Defining One Standard
The standard fits in a paragraph. A point in time, anything that happened or will expire at a moment, is an Instant, or an OffsetDateTime when the offset matters, written as ISO-8601 in UTC: 2024-05-01T21:30:00Z. A calendar date without time, such as a delivery date or a birthday, is a LocalDate: 2024-05-03. A future local event, such as a store opening at 09:00, is a local time with a zone id. The user's time zone is never baked into data; the app converts for display using the device's zone.
We write the standard into the API guidelines with examples and the matching OpenAPI formats (date-time and date), and we name an owner who answers questions, because edge cases will come up in thirty teams.
3Rolling It Out Through Shared Code
Most of the change can be made once. The platform starter configures Jackson so that java.time values are written as ISO strings, not timestamps, and it removes the reason teams replaced the mapper by offering the settings they needed. Shared DTO libraries, such as the common order and customer types, switch their timestamp fields from LocalDateTime to Instant. A small helper, or simply the rule to inject a Clock set to UTC, replaces LocalDateTime.now() in service code.
Notice that the Berlin order placed at 23:30 local time becomes 21:30Z, which the app shows correctly as 23:30 in Berlin and 17:30 in New York. Notice also that the delivery date lost its fake time and zone: a calendar day stays the same day everywhere.
Stored data needs a migration where the old values were local times. For a column that held Berlin wall-clock time, we convert each value with the Europe/Berlin zone into a UTC timestamp, which handles the historical daylight saving changes correctly, and switch the column to timestamptz. We do it per service, with the zone recorded in the audit, because guessing the zone is how the problem started.
4Handling the Clients
Changing createdAt from 2024-05-01T23:30:00 to 2024-05-01T21:30:00Z changes both the format and the value, and old app versions stay installed for months. So each changed field is treated as an API change. For fields whose format changes in a way old parsers reject, we add a new field (createdAtUtc) or a new API version, keep the old field until usage of old app versions drops below an agreed threshold, and then remove it. For fields where the app team confirms the parser accepts both forms, we document the change and switch directly.
We coordinate with the mobile teams on one plan rather than thirty: a list of fields, the release in which each changes, and the app version that handles the new format. The apps convert to the device zone for display, which also removes their own time zone guesswork.
- Audit every date fieldtype, server zone, client symptom
- Publish the standardInstant in UTC,
LocalDate, zone ids for local events - Update starter and shared DTOsone change, many services
- Does the change break old app parsers?YesNew field or API version, keep old oneNoDocument and switch directly
- Migrate stored local timesconvert with the recorded zone
- Contract tests in every servicedate formats checked in CI
6 steps in order. Play them, or step through them one at a time.
5Keeping It Fixed With Contract Tests
The last step is what stops the thirty-first service from repeating the mistake. Each service runs a contract test that serializes its response DTOs and checks every date field against the standard: timestamps match an ISO pattern ending in Z or an offset, dates match yyyy-MM-dd, and no arrays or offset-less date-times appear. The platform can generate this test from the OpenAPI spec, where each field's format is declared, and consumer-driven contracts from the mobile teams add the fields they depend on. An architecture rule, for example with ArchUnit, can also flag LocalDateTime in API DTO packages.
6Follow-up questions
Why not keep LocalDateTime and document that it is UTC?
Because the type cannot enforce it. Any developer can call LocalDateTime.now() on a server in another zone, and nothing will fail. Instant has no zone to get wrong, and the Z in the JSON tells every client how to read it.
How do we migrate data when we are not sure which zone it was written in?
We find out per service from the code history and deployment configuration: the server's default zone, any explicit zone in the code, and samples compared with known events such as order confirmation emails. Where it truly cannot be known, we document the uncertainty and convert with the most likely zone, rather than silently treating everything as UTC.
Should the API return times in the user's time zone?
No. The API returns UTC instants, and the client converts using the device's or the user's chosen zone. Returning local times ties responses to one user's settings, breaks caching, and makes the same data look different to different consumers.
7Conclusion
In this answer, we fixed wrong dates across 30 services by first auditing every date field and the zone behind it, then agreeing one standard: Instant or OffsetDateTime as ISO-8601 in UTC for points in time and LocalDate for dates without time. The shared starter and shared DTOs carry most of the change, stored local times are migrated with their recorded zone, changed fields are versioned or documented for mobile clients with a single coordinated plan, and contract tests on date formats keep every service on the standard.
Open with
First I'd audit, because thirty services usually have several different bugs: LocalDateTime written on servers in different default zones, epoch arrays from a custom ObjectMapper, calendar dates sent as midnight timestamps that shift a day in other zones.
Then, if they want more
For each field I'd record the type and which zone the values really are in, because that's needed for data migration.
Then one standard for everyone: anything that is a point in time is an Instant, or OffsetDateTime if the offset matters, written as ISO-8601 in UTC with a Z; anything that is just a calendar day is a LocalDate like 2024-05-03; and future local events keep a zone id. The app converts to the device zone for display.
Most of the rollout goes through shared code: the platform starter configures Jackson to write ISO strings, shared DTOs switch from LocalDateTime to Instant and LocalDate, and services use an injected UTC Clock. Stored local times are converted with the zone from the audit.
For clients, every changed field is an API change, so where old app parsers would break I'd add a new field or version and keep the old one until old app versions fade out, coordinated with the mobile teams as one plan.
Finally, contract tests in every service check the date formats, generated from the OpenAPI spec, so new services can't drift again.
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
- Spring Framework reference, Spring Web MVC
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 "Mobile clients in different time zones see wrong dates because services use...": https://scrivio-interview-library.netlify.app/spring-boot/json-serialization/4c7a84c64f/