从日期('r“)删除小时,分钟和秒[关闭]

I have a date with this format :

date("r",$dateMktime);

In $dateMktime, i only have year, month and day and i'm obliged to use date("r") format.

How can i remove hour, minute and seconde ? I don't want to see 00:00:00 when i echo my date.

Any idea ? Thanks :)

Edit : I can't use a different format, it's an obligation to use date('r'), i can only do echo date("r",$dateMktime);

"r" is just a shortcut to give a date formatted as "Thu, 21 Dec 2000 16:01:07 +0200".

You can use another format string, see http://php.net/manual/en/function.date.php for more information.

Try date("D, j M Y",$dateMktime);.

If you really want to use date("r",$dateMktime);, try:

implode(" ",array_slice(explode(" ",date("r",$dateMktime)),0,4));

This basically just splits on the spaces, slices out the first 4 tokens, and joins them back up.

Why not reconverting and then formatting ? If you are "obligated" to use r ?

$date = date("r", $dateMktime);
echo date('D, j M Y', strtotime($date));

Well according to the documentation of date, date('r') does include the time. Use date('Y-m-d') instead. If you can't change it, you could remove the rest using string functions.

$date=date("r",$dateMktime);
$d=explode(" ",$date);
$newdate=$d[0]." ".$d[1]." ".$d[2]." ".$d[3];
echo $date." - ".$newdate;

You may try something like;

$dateMktime = "Thu, 21 Dec 2000 16:01:07 +0200";
$datearray = (explode(" ",$dateMktime));
echo $datearray[3];//this will return 2000

You can join specific parts of this array to get your custom date format. For example;

echo $datearray[1]." ".$datearray[2]." ".$datearray[3];//this will return 21 Dec 2000