I'm building a web app where I need to store the user's birthday in the database and then display it on their profile. Naturally, birthdays shouldn't depend on the timezone.
My problem is on the javascript client, the new Date()
object operates on the user's local timezone even if the underlying date is in UTC.
If the user is in the GMT+02:00 timezone and selects a birthday of January 1, 2000 00:00
, that date in UTC will be December 31, 1999 23:00
.
The problem is displaying that date back to the user on their profile. What if the user suddenly travels to a different timezone, say GMT-05:00 and looks at their profile? They will see December 31, 1999
as their birthday.
How does one deal with dates that should be the same regardless of timezone within a Javascript frontend and a server? In what format should they be stored in the database? And how do you display them indifferent of current timezone?