PHP date("H:i (d.m.Y)",$timestamp)
function represents exact midnight as 00:00 of following day. But I need it to represent it as 24:00 of preceding day. Is it possible to be done without writing completely new date() parser function?
edit: Why do I need such 'weird' format? Because my client demands it. In my country (CZ), 24:00 is sometimes used when referring to exact midnight.
edit2: My current 'dirty' solution is: (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);
}
php //current Date, i.e. 2013-08-01 echo date("Y-m-d"); //current Time in 12 hour format, i.e. 08:50:55pm echo date("h:i:sa"); //current Time in 24 hour format, i.e. 18:00:23 echo date("H:i:s"); //current Month, i.e. 08 echo date("m"); //current Month name, i.e. Aug echo date("M"); ?>
PHP date() Function The PHP date function is used to format a date or time into a human readable format. It can be used to display the date of article was published. record the last updated a data in a database.
date_default_timezone_set('UTC'); echo "<strong>Display current date dd/mm/yyyy format </strong>". "<br />"; echo date("d/m/Y"). "<br />"; echo "<strong>Display current date mm/dd/yyyy format</strong> "."<br />"; echo date("m/d/Y")."<br />"; echo "<strong>Display current date mm-dd-yyyy format </strong>".
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 (that I tested)
So H:i:s
works for example
It will need some extra work to for for formats like "\H\i Y-m-d"
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