0

我在几个文化季节都有戏剧表演日期。

文化季节是从九月的第一天到八月的最后一天。

使用 PHP,我需要知道“九月最后一天”相对于节目日期的年份,以便为节目分配正确的季节。

例如:

15/05/2009 -> 01/09/2008 : season 2008-2009
21/06/2013 -> 01/09/2012 : season 2012-2013
27/10/2013 -> 01/09/2013 : season 2013-2014
4

2 回答 2

1

试试这个...会给你这个时期的开始年份。

$targetTime = strtotime("2013-06-05");
$sept1 = strtotime("September 1st", $targetTime);
if ($targetTime < $sept1){
    $sept1 = strtotime("-1 Year", $sept1);
} 
$year =  date("Y", $sept1);
于 2013-06-06T04:50:51.197 回答
0
<?php


function season($date)
{

    if($date->format('m') < 9)
        return $date->format('Y') -1;

    else
        return $date->format('Y') ;

}


$date = new DateTime();
$date->setDate(2008, 9, 1);
$season = season($date);
echo 'season ' . $season . '/' . ($season + 1);

?>
于 2013-06-06T05:02:26.480 回答