Zend_Date is really a time saver class, I use it in almost every project I work, It handles time_zones, and date formatting pretty easy, leaving me more time to focus on other things.

The files that I need to use Zend_Date as a standalone class are:

Date.php and the Date folder from the Zend distribution package, and this is how I use it:

  1. <?php
  2. set_include_path('./lib' . PATH_SEPARATOR . get_include_path());
  3. include_once 'Zend/Date.php';
  4. $tugId = isset($_GET['tugId']) ? (int) $_GET['tugId'] : false;
  5. function formatDate($date) {
  6. /**
  7. * List of supported timezones
  8. * http://php.net/manual/en/timezones.php
  9. */
  10. if ($date) {
  11. $fmtDate = new Zend_Date($date, Zend_Date::ISO_8601);
  12. $fmtDate->setTimezone('America/Los_Angeles');
  13. return $fmtDate->toString(Zend_Date::DATETIME);
  14. } else {
  15. return '';
  16. }
  17. }
  18. if (is_int($tugId)) {
  19. $sql = 'SELECT modified_date FROM tuggler WHERE tug_id = ' . $tugId;
  20. $result = $db->fetchAssoc($sql);
  21. $response = 'Last Record Update: '.formatDate($row['modified_date']) .'';
  22. } else {
  23. $response "nothing to return";
  24. }
  25. echo $response;

The response from the above would be Jul 9, 2009 11:41:20 AM but I can easily change it using one of the predefined constants, or I can make my own format.