Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Unix Timestamps? (http://www.programmingforums.org/showthread.php?t=13580)

grimpirate Jul 18th, 2007 12:39 AM

Unix Timestamps?
 
I'm a bit confused regarding the Unix timestamps in PHP. When I use the function time() I get a Unix timestamp. However, does this returned timestamp contain in it daylight savings and timezone offsets? Or does the number solely represent a GMT timestamp? Is it the power of the date() function that takes the timezone and dst into effect? Any suggestions on this riddle? I ask because I have a timestamp that is offset from GMT which I convert into a unix timestamp using strtotime() and I need to compare it to the current date unix timestamp to see if it has expired. However I can't compare timestamps in different timezones. So will time() and strtotime() yield Unix timestamps which are in the same timezone? Wow that's confusing. :confused:

DaWei Jul 18th, 2007 7:20 AM

A timestamp is the number of seconds elapsed since midnight, January 1, 1970, GMT. At any moment, at any place in the world (or out of the world, for that matter), that number is the same.

Have you referred to the PHP manual? For instance,
Quote:

int strtotime ( string $time [, int $now] )

The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT), relative to the timestamp given in now, or the current time if none is supplied.

This function will use the TZ environment variable (if available) to calculate the timestamp. Since PHP 5.1.0 there are easier ways to define the timezone that is used across all date/time functions. That process is explained in the date_default_timezone_get() function page.

grimpirate Jul 18th, 2007 2:47 PM

I did refer to the manual first and it was two things which confused me, perhaps due to lack of reading comprehension on my own part. Namely
Quote:

relative to the timestamp given in now ... This function will use the TZ environment variable (if available) to calculate the timestamp
In any case I've just decided to work on the assumption that both time() and strtotime() produce timestamps that can be compared equivalently.

Komodo Jul 25th, 2007 8:18 PM

I noticed that during the winter windoes says my timezone is GMT-5, and in the summer it is GMT-4. so the timezone shouldn't make a difference, although whether it does or not I haven't the slightest.


All times are GMT -5. The time now is 2:44 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC