Question

My PHP timezone is 'Asia/Tehran' so I would not expect gmmktime give me the same result as mktime.

php info:

Default timezone Asia/Tehran

However when I type in my php console:

echo date('jS F Y h:i:s A (T)', mktime());

3rd September 2013 11:23:10 AM (IRDT)

echo date('jS F Y h:i:s A (T)', gmmktime());

3rd September 2013 11:23:16 AM (IRDT)

While I expect 3.5 or 4.5 hours time difference. Am I making a mistake somewhere?

Was it helpful?

Solution

you need to give Argumente inside of gmmktime(). Your mistake is, understand first mktime() vs gmmktime(). see this link.

And The workaround is simple, use gmdate() function to display dates created with gmmktime().

<?php
  $inputDate = gmmktime(0,0,0,2,7,2012);
  echo gmdate("M d Y H:i:s O", $inputDate);
  // Feb 07 2012 00:00:00 +0000
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top