Page 141 - Open Soource Technologies 304.indd
P. 141
Open Source Technologies
Notes echo date (“Y-m-d (H:i:s)\n”, $ts);
$ts += (24 * 60 * 60);
}
?>
Output is
2004-10-29 (12:00:00)
2004-10-30 (12:00:00)
2004-10-31 (11:00:00)
2004-11-01 (11:00:00)
However, there is still a difference in the time. A better solution is to abuse
the mktime() function a little.
<?php
/* We loop for 6 days */
for ($i = 0; $i < 6; $i++) {
$ts = mktime(0, 0, 0, 10, 30 + $i, 2004);
echo date (“Y-m-d (H:i:s) T\n”, $ts);
}
?>
Output is
2004-10-30 (00:00:00) CEST
2004-10-31 (00:00:00) CEST
2004-11-01 (00:00:00) CET
2004-11-02 (00:00:00) CET
2004-11-03 (00:00:00) CET
2004-11-04 (00:00:00) CET
We add the day offset to the mktime() parameter that describes the day of month. mktime()
then correctly wraps into the next months and years and takes care of the DST hours, as you
can see in the previous output.
Sometimes, you want to show a formatted time in the current time zone and
in other time zones as well. The following script shows a full textual date
representation for the U.S., Norway, the Netherlands, and Israel:
<?php
echo strftime(“%c\n”);
echo “\nEST in en_US:\n”;
136 LOVELY PROFESSIONAL UNIVERSITY