簡體   English   中英

格式為{day-month-year}的單獨日期

[英]Separate date in the format {day-month-year}

我有一個以這種格式打印日期的代碼, Sun, 09 Mar 2014 08:31:14 GMT

我想拍攝日期並縮短日期以便打印

  • 那天
  • 這個月
  • 那一年

但是我想分別打印每個月,我想打印月份的數字

這是我嘗試的代碼

$Date = $item->pubDate;
echo '.$Date.';

您應該使用DateTimeClasscreateFromFormat

<?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

演示版

嘗試使用日期功能

echo date('d-m-Y', strtotime($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 = '08/02/2014';
list($month, $day, $year) = explode('/', $date);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM