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.

Community
  • 1
  • 1

3 Answers3

0

This is probably due to the TimeZone setting. Learn about PHP date_default_timezone_set() and make sure your local time zone matches the timezone you really want. All Unix Timestamps are the same world-wide. But the local DATETIME values vary around the globe. This article may be visible to you (hope so):

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

Best regards, ~Ray

CodeZombie
  • 5,367
  • 3
  • 30
  • 37
Ray Paseur
  • 2,106
  • 2
  • 13
  • 18
0

It is definetily the timezone setting in your local web server.

Check the php.ini for date.timezone value. It also may be overridden by htaccess file or you PHP script.

Laurynas MaliĊĦauskas
  • 1,909
  • 1
  • 19
  • 34
0

strtotime was included once DateTime was created. The parsing is dependant of the server default timezone.

If you want get your date with the good timezone, there are two ways :

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

or :

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

you can find more informations here .

artragis
  • 3,677
  • 1
  • 18
  • 30