I use LocalDateTime for all timestamps in the RESTful web service and all timestamps initialization and changes are made on the server.
When the client of the service creates some resource then the server internally assigns creation timestamp to this resource.
class Resource {
private String data;
private LocalDateTime creationTimestamp;
public Resource(String someData) {
this.data = someData;
this.creationTimestamp = LocalDateTime.now();
}
}
The server returns a resource back in JSON format:
{
"data" : "someData",
"creationTimestamp" : "2017-09-22T12:03:44.022"
}
When the client renders creationTimestamp
it doesn't know the server timezone in which this timestamp was created and renders time incorrectly.
I see the only way to solve it: change all timestamps in the application to ZonedDateTime and return them back to the client together with timezone in JSON. But this approach is very expensive.
Is there any other way to solve this problem?