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

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


当前回答

我是这么做的:

<?php echo date("d-m-Y") ?>

下面是对它功能的一些解释:

d = day
m = month
Y = year

Y表示四位数(如1990),Y表示两位数(如90)

其他回答

如果你的服务器支持短标签,或者你使用PHP 5.4,你可以使用:

<?=date("Y")?>

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

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

http://us2.php.net/date

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
?>
print date('Y');

有关更多信息,请查看date()函数文档:https://secure.php.net/manual/en/function.date.php