Formatting a Specific Date
All previous phrases in this chapter have used the current date and time. However, it is also possible to use any other arbitrary date and time value. For this, the relevant functions (especially date() and strftime()) accept a second parametera time stamp of the date to be analyzed. This time stamp is an integer value, the date and time in the so-called epoche format. This is the number of seconds that passed since January 1st, 1970, midnight GMTthe beginning of the UNIX epoche. The time stamp/epoche value of the current moment can be retrieved using time() or by calling date('U') (see Table 3.1). If you want to use another date, mktime() comes into play. This function converts a date provided by year, month, day, hour, minute, and second into an epoche value. Probably the strangest thing about this function is the order in which these parameters are passed:
You can also provide an optional seventh parameter, regardless of whether it is Daylight Savings Time (DST). This is relevant close to the change from or to DST because that does not happen at the same time over the world. The preceding code calculates the time stamp for noon on the first day of this millennium. Because there was no year 0, this was January 1st, 2001. |