在每年的特定日期将显示年份更改为下一年

时间:2016-09-30 15:01:03

标签: php date

好的,所有,我有一个窘境。我有一个应用程序,需要更新2016年10月1日上午12点按钮上显示的2017-2018年。它必须保持这种状态,直到明年10月1日,它将再次更新到2018-2019。我如何在php中写这个?

1 个答案:

答案 0 :(得分:0)

您可以尝试类似

的内容
//the year from is the current year
$yearFrom = date("Y");

//if it's october or later, make the year from NEXT year
if (date("n")>=10) $yearFrom++;

//the year to is always the year after the year from
$yearTo = $yearFrom + 1;

然后在按钮内

echo $yearFrom."-".$yearTo;