[英]get an hour wrong when using UNIX_TIMESTAMP and time()
I have set my mysql db: SET time_zone = 'America/Los_Angeles';
我已经设置了我的mysql数据库:
SET time_zone = 'America/Los_Angeles';
and in php 和在PHP
date_default_timezone_set('America/Los_Angeles');
but when I add 但是当我添加
$time = strtotime ("+2 minutes");
and 和
$time2 = gmdate("Y-m-d H:i:s", $time);
to the db i get wrong an hour wrong when I get it from mysql like this: 到数据库我错了一个小时,当我从mysql那里得到这样的错误:
$query ="select UNIX_TIMESTAMP("time"), time2 from tbl;
if ($result = $conn->query($query)) {
while ($row = $result->fetch_assoc()) {
$unix_time = $row["UNIX_TIMESTAMP("time")"];
$unix_time2 = $row["time2"];
}
$result->close();
} ,
echo gmdate("Y-m-d H:i:s", $unix_time)." | ".gmdate("Y-m-d H:i:s", $unix_time2)." ";
displays: 显示:
2010-12-26 01:06:48
| 2010-12-26 01:06:48
| 2010-12-26 02:06:24
unix_timestamp()
will retrieve your local timestamp, which is currently in daylight savings mode. unix_timestamp()
将检索您的本地时间戳,当前处于夏令时模式。 gmdate()
works off Greenwhich Mean Time, aka UTC, which has no DST, so you'll get the 1 hour difference. gmdate()
可以在格林威治标准时间(又名UTC)下运行,因为它没有夏令时,所以您会得到1小时的时差。 Use date()
instead of gmdate()
to work with DST-awareness. 使用
date()
而不是gmdate()
可以进行DST感知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.