简体   繁体   中英

MySQL EST timestamp filed showing 1 hour difference in php

When I run this SELECT DATE_FORMAT(NOW(),'%Y-%m-%d %r') in mysql its showing 2015-09-08 01:47:06 AM . My MySQL system timezone is EDT . However when I run this in PHP in same time like

<?php 
date_default_timezone_set('EST');
echo date('Y-m-d h:i:s A');
//also tested :output 2015-09-08 00:47:06 AM
//echo date('Y-m-d H:i:s A');
?>

Its showing 2015-09-08 12:47:06 AM . So its 1 hour difference between this two time. Whats wrong here? how can I get same as mysql NOW() in PHP?

You're setting the time zone as EST - that's Eastern Standard Time, which is UTC-5 all year round. If you actually want "Eastern Time", use America/New_York as your time zone identifier. That will vary between EST and EDT at the appropriate times.

I would strongly recommend avoiding using the abbreviations as far as you possibly can - they're not even properly unique (BST = British Standard Time and British Summer Time, as one example) and cause a lot of confusion. Basically they typically represent one particular UTC offset. That's not the same as a time zone, which represents how the UTC offset varies over time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM