0

I have the following json object:

public class User {
   private String name;
   @JsonFormat(pattern="dd-MM-yyyy")
   private Date birthdate;
}

but I'm thinking of changing it to:

private String birthdate; //mmm...now need to make sure the format is respected..

Problem is that this object has to be saved inside of a DB and then retrieved. Suppose I have an user in the CEST time, while my application's time is UTC, so 2 hours behind.

They send "15-04-1990" (time is implicitely 00:00:00), the system then interprets this date as "14-04-1990"(time is implicitely 10:00:00 PM) due to the 2 hours difference. When they go retrieve the information again they will see 14-04-1990!

Ok, I could just add the sender's timezone to the request. But I don't like it: take a 3rd party residing on the application's country wanting to check some information (for example an helpdesk operator): they would still see the date in the wrong timezone!

So, do you see any problem in receiving the date as string? And if that would be fine how to make sure that the string contains a date formatted in "dd-mm-yyyy"?

Phate
  • 6,066
  • 15
  • 73
  • 138
  • I will usually store everything in the back-end in UTC, and then adjust that on the the client-side based on their timezone/locale. – Popmedic May 19 '18 at 15:23
  • Problem is that we are not talking about a timestamp, here I just want to store the birthdate.The user would see the day before... – Phate May 19 '18 at 15:26
  • Are you trying to get the clients timezone offset from GMT??? This post shows you how to do that 2 ways in Java. https://stackoverflow.com/questions/16525617/how-to-detect-users-timezone/16526897#16526897 – Popmedic May 19 '18 at 15:49

1 Answers1

0

One of things could be to save the date and time objects as timestamp of GMT and then change every time zone with respect to that.