Php 格式为{day month year}的单独日期

Php 格式为{day month year}的单独日期,php,function,datetime,output,Php,Function,Datetime,Output,我有一个以这种格式打印日期的代码 Sun,2014年3月9日08:31:14 GMT 我想把日期缩短以便打印 那天 月份 年度 但是我想分别打印每个,我想用数字打印月份 这是我试过的代码 $Date = $item->pubDate; echo '.$Date.'; 尝试使用函数 如果你想一个接一个的回应 $date_to_time = strtotime($Date); //Day echo date('d', $date_to_time); //Month echo date(

我有一个以这种格式打印日期的代码
Sun,2014年3月9日08:31:14 GMT

我想把日期缩短以便打印

  • 那天
  • 月份
  • 年度
但是我想分别打印每个,我想用数字打印月份

这是我试过的代码

$Date = $item->pubDate;
echo '.$Date.';
尝试使用函数

如果你想一个接一个的回应

$date_to_time = strtotime($Date);

//Day
echo date('d', $date_to_time);
//Month
echo date('m', $date_to_time);
//Year
echo date('Y', $date_to_time);
尝试使用函数

如果你想一个接一个的回应

$date_to_time = strtotime($Date);

//Day
echo date('d', $date_to_time);
//Month
echo date('m', $date_to_time);
//Year
echo date('Y', $date_to_time);
试一试

试一试

您应该使用
DateTimeClass

<?php
$dt='Sun, 09 Mar 2014 08:31:14 GMT';
$date = DateTime::createFromFormat('D, d M Y G:i:s O', $dt);
echo "Day : ".$date->format('d'); // 09
echo "Month : ".$date->format('m'); //03
echo "Year : ".$date->format('Y'); //2014
您应该使用
DateTimeClass

<?php
$dt='Sun, 09 Mar 2014 08:31:14 GMT';
$date = DateTime::createFromFormat('D, d M Y G:i:s O', $dt);
echo "Day : ".$date->format('d'); // 09
echo "Month : ".$date->format('m'); //03
echo "Year : ".$date->format('Y'); //2014