PHP, MySQL

This question already has an answer here:

  • Should I use the datetime or timestamp data type in MySQL? 33 answers

  • You are mixing up client timezone and server timezone.

    As long as you do not care where your users sit, you have absolutely no problem as long as you do not change the server timezone. You can set a default timezone in MySQL and in PHP and this one will be used, independent of the timezone of the visitor.

    If you want to respect the timezone of your visitors, it gets slightly more complicated. You need do transform a timestamp from one timezone into another. You can find information concerning that in the PHP manual if you want to achieve this with PHP. You can read this SO thread if you are interested in how MySQL stores dates internally (difference between TIMESTAMP and DATETIME type), which opens the possibility to use some of mysql's features, and which you should definitely take into account when you implement a global project.


    Timezone can be configured dynamically in the PHP, so you don't need to store time offsets in your DB. Storing unix timestamp is a good solution.


    You can store timestamp as INTEGER datatype.

    Then, you can use JS on client side to get the timezone of user.

    链接地址: http://www.djcxy.com/p/25104.html

    上一篇: Mysql数据库表中的Datetime和Timestamp

    下一篇: PHP,MySQL