3

I know it's gonna sound you strange.. but it's happening..

I am trying mktime() function to create a seconds string:

$time = mktime(21,0,0,3,29,2014);
echo date("d-M, h:i A", $time);

And then I add 21600 (6 Hours) seconds in it..

 $newstr = $time+21600;
 echo  echo date("d-M, h:i A", $newstr);

I Expect this output:

29-Mar, 09:03 PM
30-Mar, 03:03 AM

But I am getting this:

29-Mar, 09:03 PM
30-Mar, 04:03 AM      // It must be 03:03 AM

Any one knows what the problem is..? I am using xampp.

Ahmad Sattar
  • 321
  • 2
  • 10

2 Answers2

3

Your timezone is set to a region for which Daylight Savings Time is enacted on March 30, 2014, so the latter date ends up being adjusted to DST and is one hour later than you'd expect mathematically.

http://www.timeanddate.com/news/time/europe-starts-dst-2014.html

You can verify this by printing your before and after dates with the timezone marker e and DST marker I included in date's mask.

faintsignal
  • 1,828
  • 3
  • 22
  • 30
0

Maybe you can try to add this line before your code

ini_set('date.timezone','UTC');
Mathieu
  • 38
  • 7