PHP date () print 24:00 instead of 00:00

The PHP function date("H:i (d.m.Y)",$timestamp)represents the exact midnight at 00:00 the next day. But I need him to present him as 24:00 the previous day. Is it possible to do this without writing a completely new date () parser function?

edit: Why do I need such a "strange" format? Because my client requires it. In my country (CZ), 24:00 is sometimes used when it comes to exact midnight.

edit2: My current dirty solution: (does not work with all possible format strings)

function date_24midnight($format,$ts)
{
   if(date("Hi",$ts)=="0000")
      return preg_replace('/23:59/',"24:00",date($format,$ts-1));
   else
      return date($format,$ts);
}
+4
source share
1 answer
function date_24midnight($format,$ts)
{
   if(date("Hi",$ts)=="0000") {
      $replace = array(
        "H" => "24",
        "G" => "24",
        "i" => "00",
      );

      return date(
        str_replace(
          array_keys($replace),
          $replace, 
          $format
        ),
        $ts-60 // take a full minute off, not just 1 second
      );
   } else {
      return date($format,$ts);
   }
}

This function is based on yours, but works for all formats (which I tested)

, H:i:s , ,

, "\H\i Y-m-d"

,
+2

All Articles