Immitate PHP 5.3 DateTime in PHP 5.2 Immitate PHP 5.3 DateTime in PHP 5.2 php php

Immitate PHP 5.3 DateTime in PHP 5.2


The last line would have to be translated to

echo '<h3>' . $reqDate->format('U') . '</h3>';

in order to work with PHP 5.2. Other that that, it looks fine.

Edit:You could subclass DateTime to provide a forwards compatible solution:

class MyDateTime extends DateTime {    public function getTimestamp() {         return method_exists('DateTime', 'getTimestamp') ?              parent::getTimestamp() : $this->format('U');    }}


This is a pretty complete DateTime 5.2 extension. Look for my comment for setTimestamp to fix your time_zone issues though

https://gist.github.com/SeanJA/349273