2016-09-30 50 views
-1

好吧,我有一个窘境。我有一个应用程序,需要将2016年10月1日上午12点按钮上显示的2017-2018年更新。它必须在明年10月1日之前一直保持到明年,并将再次更新至2018-2019年。我如何在PHP中写这个?每年在特定日期将显示年份更改为下一年

+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; 
+0

这是什么是在当前代码: '

<?php echo date(“Y”); ?> - <?php echo date(“Y”,strtotime(“+ 1 year”)); ?>

相关问题