gmmktime and mktime give me the same number

1k views Asked by At

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?

1

There are 1 answers

1
KarSho On BEST ANSWER

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
?>