Javascript 如何在php中设置自定义月份开始日期和结束日期

Javascript 如何在php中设置自定义月份开始日期和结束日期,javascript,php,mysql,Javascript,Php,Mysql,我的工资月从上个月26号开始,到本月25号结束 ie二月月份为2016-01-26至2016-02-25 我需要如下所示的输出 $date = '2014-02-27'; echo date('F', strtotime($date)); = "March" //if date > 25 print next month 我相信你所要做的就是得到这一天: $date = '2014-02-27'; $day = date('d', strtotime($date)); 然后看看

我的工资月从上个月26号开始,到本月25号结束 ie二月月份为2016-01-26至2016-02-25

我需要如下所示的输出

$date = '2014-02-27';  
echo date('F', strtotime($date)); = "March" //if date > 25 print next month

我相信你所要做的就是得到这一天:

$date = '2014-02-27';  
$day = date('d', strtotime($date));
然后看看是否大于26,增加一个月

$month = date('F', strtotime($date));

if($day > 26)
{
$ts = mktime(0, 0, 0, date("n", strtotime($date)) + 1, 1);
$tmpNewDate = date("Y-m-d H:i:s", $ts);
$month = date('F', strtotime($date));

}

echo $month;

我相信你所要做的就是得到这一天:

$date = '2014-02-27';  
$day = date('d', strtotime($date));
然后看看是否大于26,增加一个月

$month = date('F', strtotime($date));

if($day > 26)
{
$ts = mktime(0, 0, 0, date("n", strtotime($date)) + 1, 1);
$tmpNewDate = date("Y-m-d H:i:s", $ts);
$month = date('F', strtotime($date));

}

echo $month;

试试这个,我准备了几个日期输入:

<?php
    $input_date = '2014-2-2';
    // $input_date = '2014-2-27';
    // $input_date = '2014-12-27';
    $date = DateTime::createFromFormat('Y-m-d', $input_date);
    $next_month = null;
    $year = $date->format('Y');
    $next_month = $date->format('m');
    if ($date->format('d') >= 26)
        $next_month = intval($date->format('m')) + 1;       
    if ($next_month == 13){
        $next_month = 1;
        $year = intval($year) + 1;
    }
    echo "next month = " . $next_month . ", year = " . $year;
?>

试试这个,我准备了几个日期输入:

<?php
    $input_date = '2014-2-2';
    // $input_date = '2014-2-27';
    // $input_date = '2014-12-27';
    $date = DateTime::createFromFormat('Y-m-d', $input_date);
    $next_month = null;
    $year = $date->format('Y');
    $next_month = $date->format('m');
    if ($date->format('d') >= 26)
        $next_month = intval($date->format('m')) + 1;       
    if ($next_month == 13){
        $next_month = 1;
        $year = intval($year) + 1;
    }
    echo "next month = " . $next_month . ", year = " . $year;
?>


那么你想打印结束日期?那么你想打印结束日期?嗨@peter我想这一定是$month=date('F',strotime($date))$月=日期('F',标准时间($tmpNewDate));嗨@peter我想这一定是$month=date('F',strottime($date))$月=日期('F',标准时间($tmpNewDate));