我想在一个网站的页脚放一个版权声明,但我认为这对于过时的年份来说是非常俗气的。

如何在php4或php5中自动更新年份?


当前回答

<?php echo date("Y"); ?>

这段代码应该

其他回答

全年使用:

 <?php 
    echo $curr_year = date('Y'); // it will display full year ex. 2017
?>

或者只得到两位年份,就像这样:

 <?php 
    echo $curr_year = date('y'); // it will display short 2 digit year ex. 17
?>

如果你正在使用碳PHP API扩展DateTime,你可以很容易地实现:

<?php echo Carbon::now()->年;? >

echo date('Y')给你当前年份,这将自动更新,因为date()给我们当前日期。

strftime("%Y");

我喜欢strftime。这是一个抓取/重新组合日期/时间块的很棒的函数。

此外,它尊重区域设置,日期函数不这样做。

<?php echo date("Y"); ?>