0

I am trying to convert 1355657846 and 1355677646 unix timestamp to Y-M-D H:i:s format. The problem is in H:i:s . It should be 11:37:24 and 17:07:26 respectively but it is showing 12:37:24 and 18:07:26.

<?php

echo date('Y-m-d H:i:s','1355657846');//2012-12-16 12:37:26,must be 11:37:26

echo date('Y-m-d H:i:s','1355677646');//2012-12-16 18:07:26,must be 17:07:26

?>

It should be 11:37 and 17:07 because I checked it in unix timestamp conversion

and also it is the time I had received mail in gmail account. And I got these unix timestamp from gmail( using php imap function...$overview->udate)

I am testing this on local xampp server. Can anyone suggest me where I am going wrong here?

PS: I checked related question in stackoverflow, but here I want to convert timestamp to datetime, which I think should be constant irrespective of timezone.

4

3 回答 3

0

这可能是由于 TimeZone 设置。了解 PHPdate_default_timezone_set()并确保您的本地时区与您真正想要的时区匹配。所有 Unix 时间戳在全球范围内都是相同的。但是本地 DATETIME 值在全球范围内有所不同。您可能会看到这篇文章(希望如此):

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

最好的问候,~雷

于 2012-12-16T14:41:25.487 回答
0

它绝对是您本地 Web 服务器中的时区设置。

检查 php.ini 中的 date.timezone 值。它也可能被 htaccess 文件或您的 PHP 脚本覆盖。

于 2012-12-16T14:41:54.367 回答
0

创建 DateTime 后包含 strtotime。解析取决于服务器默认时区。

如果您想在合适的时区找到您的日期,有两种方法:

default_timezone_set('Europe/Paris');//for example 

或者 :

$date = DateTime::createFromFormat('U',$timestamp,new DateTimezone('Europe/Paris'));
echo $date->format('Y-m-d H:i:s);

你可以在这里找到更多信息。

于 2012-12-16T14:42:57.083 回答