[英]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
.当我在 mysql 中运行这个
SELECT DATE_FORMAT(NOW(),'%Y-%m-%d %r')
它显示2015-09-08 01:47:06 AM
。 My MySQL system timezone is EDT
.我的 MySQL 系统时区是
EDT
。 However when I run this in PHP in same time like但是,当我同时在 PHP中运行它时
<?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
.它的显示时间为
2015-09-08 12:47:06 AM
。 So its 1 hour difference between this two time.所以这两个时间之间相差1小时。 Whats wrong here?
这里有什么问题? how can I get same as mysql
NOW()
in PHP?如何在 PHP 中获得与 mysql
NOW()
相同的功能?
You're setting the time zone as EST
- that's Eastern Standard Time, which is UTC-5 all year round.您将时区设置为
EST
- 即东部标准时间,全年都是 UTC-5。 If you actually want "Eastern Time", use America/New_York
as your time zone identifier.如果您确实想要“东部时间”,请使用
America/New_York
作为您的时区标识符。 That will vary between EST and EDT at the appropriate times.这将在适当的时间在 EST 和 EDT 之间有所不同。
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.我强烈建议您尽可能避免使用这些缩写——它们甚至不是唯一的(例如,BST = 英国标准时间和英国夏令时)并且会引起很多混淆。 Basically they typically represent one particular UTC offset.
基本上,它们通常代表一个特定的 UTC 偏移量。 That's not the same as a time zone, which represents how the UTC offset varies over time.
这与时区不同,时区表示 UTC 偏移量随时间变化的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.