Php 以不同格式获取日期
我只是想知道如何在这一个php日期。“2015年4月4日至25日” 此表的表结构类似于“日期开始=04-04”和“日期结束=04-25”以及“年份=2015” 关于,请尝试此代码Php 以不同格式获取日期,php,date,Php,Date,我只是想知道如何在这一个php日期。“2015年4月4日至25日” 此表的表结构类似于“日期开始=04-04”和“日期结束=04-25”以及“年份=2015” 关于,请尝试此代码 $date_start = "04 - 04"; $date_end = "05 - 25"; $year = "2015"; $date_start = preg_replace('/\s+/', '', $date_start); $date_end = preg_replace('/\s+/', '', $da
$date_start = "04 - 04";
$date_end = "05 - 25";
$year = "2015";
$date_start = preg_replace('/\s+/', '', $date_start);
$date_end = preg_replace('/\s+/', '', $date_end);
list($month1, $startDate) = explode("-",$date_start);
list($month2, $endDate) = explode("-",$date_end);
if($month1 == $month2)
{
$month1 = date("F",strtotime("2015-".$month1."-01"));
$Output = $month1." ".(int)$startDate." - ".(int)$endDate.", ".$year;
}
else
{
$month1 = date("F",strtotime("2015-".$month1."-01"));
$month2 = date("F",strtotime("2015-".$month2."-01"));
$Output = $month1." ".(int)$startDate." - ".$month2. " ". (int)$endDate.", ".$year;
}
echo $Output;
你在找这样的东西吗:
<?php
$date_start = explode(" - ","04 - 04");
$date_end = explode(" - ","05 - 25");
$year = "2015";
$monthNumStart = $date_start[0];
$monthNumEnd = $date_end[0];
if($monthNumStart == $monthNumEnd)
{
$monthName = date('F', mktime(0, 0, 0, $monthNumStart, 10));
$date = $monthName.' '.$date_start[1].' - '.$date_end[1].', '.$year;
}else{
$monthName = date('F', mktime(0, 0, 0, $monthNumEnd, 10));
$date = $monthName.' '.$date_start[1].' - '.$date_end[1].', '.$year;
}
echo $date;
?>
你试过什么吗?如果$date\u end=“05-02”
=?我已经更新了我的答案。因为它没有满足所有的要求,而现在是。如果$date\u end=“05-02”
=,请使用此选项$date_start=preg_replace('/\s+/','.$date_start);。它将从字符串中删除空白