Its prototype follows:
int mktime([int hour [, int minute [, int second [, int month
[, int day [, int year [, int is_dst]]]]]]])
The purpose of each optional parameter should be obvious, save for perhaps is_dst,
which should be set to 1 if daylight saving time is in effect, 0 if not, or ??“1 (default) if
you??™re not sure. The default value prompts PHP to try to determine whether daylight
CHAPTER 1 2 ?– D ATE AND T IME 333
saving time is in effect. For example, if you want to know the timestamp for February 24,
2007, 4:24 p.m., all you have to do is plug in the appropriate values:
echo mktime(16,24,00,2,24,2007);
This returns the following:
1172352240
This is particularly useful for calculating the difference between two points in
time. For instance, how many hours are there between now (June 4, 2007) and
midnight April 15, 2008?
$now = mktime();
$taxday = mktime(0,0,0,4,15,2008);
// Difference in seconds
$difference = $taxday - $now;
// Calculate total hours
$hours = round($difference / 60 / 60);
echo "Only $hours hours until tax day!";
This returns the following:
Only 7568 hours until tax day!
Date Fu
This section demonstrates several of the most commonly requested date-related
tasks, some of which involve just one function and others that involve some combination
of several functions.
334 CHAPTER 12 ?– D ATE AND TIME
Displaying the Localized Date and Time
Throughout this chapter, and indeed this book, the Americanized temporal and
monetary formats have been commonly used, such as 04-12-07 and $2,600.
Pages:
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410