Datetime And Leap Second

<?php

// Leap second on 2016-12-31
$date = DateTimeImmutable::createFromFormat(
    'j-M-Y H:i:s', '31-Dec-2016 23:59:60'
    );
echo $date->format('Y-m-d H:i:s');
// 2017-01-01 00:00:00


$date = DateTimeImmutable::createFromFormat(
    'j-M-Y H:i:s', '99-Dec-2016 99:99:99'
);
echo $date->format('Y-m-d H:i:s');
// 2017-03-13 04:40:39

$date = DateTimeImmutable::createFromFormat(
    'j-M-Y H:i:s', '99-Dec-2016 99:99:100'
);
var_dump($date); // false

The last leap second was added on 2016, Dec 31rst. On that day, 23:59:60 existed, and was followed by 00:00:00 on the first of January. The date time do not handle this, rand rather convert the 60 seconds into the next day, silently.

In fact, hours, minuts, seconds and day of the month, all support 2 digits, and accept values up to 99: they are all converted silently to their equivalent date, as if time of that duration passed.

Leap years, on the other hand, are all well supported.

See Also

PHP Features

Last updated: 14 July 2026