Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best practice for timezone conversions?

Tags:

php

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?

like image 578
Jim Avatar asked Feb 13 '10 01:02

Jim


People also ask

What is the best time zone to store things like when a record was added or updated?

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.

What is the correct way to write time zones?

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.


1 Answers

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

like image 141
ziya Avatar answered Oct 01 '22 22:10

ziya