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?
The widely-recommended solution for storing dates and times is to store the date and time in UTC. This means, whenever you have a user that inserts or updates a datetime value in the database, convert it to UTC and store the UTC value in the database column. Your data will be consistent.
Reference to a specific time and zone would follow standard guidelines with the zone in parentheses: 4:42 p.m. (PST), 11:03 a.m. (MDT), 2:30 p.m. (CST), 10:00 P.M. (EST). AP on the other hand advises to capitalize the full name of each time zone: Pacific/Mountain/Central/Eastern Standard Time.
Keep everything as UTC in your data store and convert at your presentation layer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With