Jump to content


Photo

mktime vs. gmmktime


  • Please log in to reply
4 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 28 May 2006 - 03:11 AM

I don't understand why this happens:

$date = getdate(mktime(0, 0, 0, 5, 27, 2006));
echo $date['weekday']; //Saturday (correct)

$date = getdate(gmmktime(0, 0, 0, 5, 27, 2006));
echo $date['weekday']; //Friday (incorrect)

What makes mktime() and gmmktime() different? I know gmmktime() is based on GMT time, but I don't understand why that makes a difference since the user is providing the date and time. Maybe I don't make sense. Let me know.
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 DaVuLf

DaVuLf
  • Members
  • PipPipPip
  • Advanced Member
  • 124 posts

Posted 28 May 2006 - 03:15 AM

Is it maybe the time zone differences? If you're ahead of GMT, maybe it is showing a different day because of that...

#3 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 28 May 2006 - 03:20 AM

Actually if it generates a timestamp there is no difference.

Basically mktime() generates local timestamps, and gmmktime() GMT timestamps.
~ D Kuang

#4 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 28 May 2006 - 03:28 AM

[!--quoteo(post=377741:date=May 27 2006, 10:20 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 27 2006, 10:20 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Actually if it generates a timestamp there is no difference.

Basically mktime() generates local timestamps, and gmmktime() GMT timestamps.
[/quote]
Ah I see, I see. I didn't really understand what a unix timestamp was. It all makes sense now. But why 1970?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#5 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 28 May 2006 - 03:36 AM

Well, it's the beginning of the UNIX epoch. (January 1 1970 00:00:00 GMT). UNIX Timestamps represents the number of seconds between the time specified and the beginning.
~ D Kuang




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users