Timezone Issue

Environment:

  • Server: MDT (UTC – 6 hours)
  • Local: Taipei Time (UTC +8 hours)

Solution:

  • date_default_timezone_set("Asia/Taipei");
    date('Y-m-d G:i:s', time()) will be Taipei time.
  • Const a variable for comparison statements:
    mysql_local_now = ' DATE_ADD(NOW(),INTERVAL 14 HOUR) '
    e.g.SELECT title from project
    where from_date > DATE_ADD(NOW(),INTERVAL 14 HOUR)

 

Others:

  • SELECT NOW( ) : will return server time. e.g. 2013-03-14 12:01:33
  • UTC_TIMESTAMP( ) : will return UTC time. e.g. 2013-03-14 18:06:01
  • date('Y-m-d G:i:s', time()): will return local time according to timezone setting.