There is a date for adding news (date ()) on the site, but if we allow a person to have a time difference of -6 hours, and I will add the news on the 5th of a o'clock in the morning, and the person who visits the site will have 4 more and see the date of the addition of the news and will be in misunderstanding, how can I fix it?

  • On the website all timestamps should be stored in time according to the Hryvnych UTC. Next are the options: 1. On the client side, the javscript code converts this time for each message / news according to the time zone specified by the client in the system. 2. The user specifies his time zone when registering or entering the site for the first time (saved in cookies for example) and then php recalculates the displayed time when generating the page in accordance with the specified time zone (on the server side). 3. By ip, we determine the region of the user's residence and recalculate the time on the server - Visman September

1 answer 1

When loading a site, write a JS code that creates a cookie in which it stores the user's time zone. Thanks to what in the backend with any request you will receive a time zone.

If you need the current time zone of the user, then after the user logs in, you read the cookie and if you have it, you compare it with the current time zone value of the user in the database - if there are changes, change it.

This solution is good because you always know the current time zone! For example, when a user changes the time zone, he simply needs to log in to the site and the updates will sit in the database.