Consider the timestamp 1172350253 (February 24, 2007 15:50:53 EST). Let??™s pass it
to getdate() and review the array elements:
Array (
[seconds] => 53
[minutes] => 50
[hours] => 15
[mday] => 24
[wday] => 6
[mon] => 2
[year] => 2007
[yday] => 54
[weekday] => Saturday
[month] => February
[0] => 1172350253
)
Working with Timestamps
PHP offers two functions for working with timestamps: time() and mktime(). The
former is useful for retrieving the current timestamp, whereas the latter is useful for
332 CHAPTER 12 ?– D ATE AND TIME
retrieving a timestamp corresponding to a specific date and time. Both functions are
introduced in this section.
Determining the Current Timestamp
The time() function is useful for retrieving the present Unix timestamp. Its prototype
follows:
int time()
The following example was executed at 15:25:00 EDT on August 27, 2007:
echo time();
This produces a corresponding timestamp:
1187897100
Using the previously introduced date() function, this timestamp can later be
converted back to a human-readable date:
echo date("F d, Y h:i:s", 1187897100);
This returns the following:
August 7, 2007 03:25:00
Creating a Timestamp Based on a Specific Date and Time
The mktime() function is useful for producing a timestamp based on a given date and
time. If no date and time is provided, the timestamp for the current date and time is
returned.
Pages:
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409