What's the best way to manage dates across PHP, MySQL, etc?

前端 未结 4 664
渐次进展
渐次进展 2021-01-03 03:52

My server is in Dallas. I\'m in New York City.. and both PHP and MySQL have configuration variables for setting the timezone.

How do I get them all to work together

4条回答
  •  难免孤独
    2021-01-03 04:18

    Record your dates in GMT (zero offset) and then calculate the offset based on the local timezone (EST is +6, for example, so you'd add 6 hours to the GMT).

    Check the Date docs for the date_default_timezone_set() function.

    Just remember, when writing to the database, you'll have to change time zones, store the date, then change back. Likewise, when you're retrieving the date, don't forget to add the timezone offset.

提交回复
热议问题