I'm working on a few years old codebase and it uses DateTime. The server is using PHP 5.2.
I see that DateTime::getTimestamp() has been added after PHP 5.3.
Is it possible to get a timestamp from DateTime in PHP 5.2?
I used get_class_methods to see if the method is available, but it's not.
Array
(
[0] => __construct
[1] => format
[2] => modify
[3] => getTimezone
[4] => setTimezone
[5] => getOffset
[6] => setTime
[7] => setDate
[8] => setISODate
)
$datetime = new DateTime();
echo $datetime->format('U');
See it in action
edit
As of PHP 5.4 you can make this a one-liner:
echo (new DateTime())->format('U');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With