Prev | Current Page 413 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

Its prototype follows:
Boolean setTime(integer hour, integer minute [, integer second])
Let??™s set the time to 8:55 p.m.:
$date = new DateTime();
$date->setTime(20,55);
echo $date->format("h:i:s");
This returns the following:
08:55:00
Modifying Dates and Times
You can modify a DateTime object using the modify() method. This method accepts
the same user-friendly syntax as that used within the constructor. For example, suppose
you create a DateTime object having the value February 28, 2007 00:33:00. Now you
want to adjust the date forward by seven hours, changing it to February 28, 2007
7:33:00:
$date = new DateTime("February 28, 2007 00:33");
$date->modify("+7 hours");
echo $date->format("Y-m-d h:i:s");
348 CHAPTER 12 ?–  D ATE AND TIME
This returns the following:
2007-02-28 07:33:00
Summary
This chapter covered quite a bit of material, beginning with an overview of several
date and time functions that appear almost daily in typical PHP programming tasks.
Next up was a journey into the ancient art of Date Fu, where you learned how to combine
the capabilities of these functions to carry out useful chronological tasks. You also
read about the useful Calendar PEAR package, where you learned how to create gridbased
calendars and validation and navigation mechanisms. Finally, an introduction
to PHP 5.1??™s object-oriented date-manipulation features was provided.


Pages:
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425