Home » Php » php – What is the best practice for timezone conversions?

php – What is the best practice for timezone conversions?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I want to give users the option to change their timezone and display their data in that timezone. I’m currently storing a unix timestamp and would like to know what the best way to handle this conversion would be.


I am storing my timestamp in unix format. My concern is what function can I use to do the conversion on the presentation layer?

How to&Answers:

Keep everything as UTC in your data store and convert at your presentation layer.

Answer:

Store date data as GMT, and in the user prefs let them store their timezone (which is simply an offset of GMT).