Question about time synchronization in mysql (so that users from different countries get the correct date and time).

The user chooses when the project will end (after 2 days, 5 days or 7 days). After that, information about the project is recorded in the database, and the Current time + number will be recorded in the field окончание проекта (TIMESTAMP). days *24*3600 .

When I sample from the database, I calculate how much time remains until the end of the project (for example: the project ends in 2 days 3 hours 46 minutes), BUT, because this time will be calculated relative to the server!

The question is: do I need to somehow synchronize the time so that users from different time zones will display the correct end time of the project (for example: the project ends in 2 days 3 hours 46 minutes).

    2 answers 2

    You can come up with many implementations (for example, even through geo ip), but many projects use a very simple and reliable way out: they ask the user to indicate his offset relative to UTC when registering. Everyone knows him, so there are no problems.

      Pass the variable with the time that is stored in the database in javascript! javascript reads the local time on the user's computer, in the same javascript write the calculation function and display the right time in the right place using the same javascript! Reference of the Date object , there are examples and methods!

      • s) someone made a response to the answer) thanks ... I hope it will be useful) - Palmervan