我想在一个网站的页脚放一个版权声明,但我认为这对于过时的年份来说是非常俗气的。
如何在php4或php5中自动更新年份?
我想在一个网站的页脚放一个版权声明,但我认为这对于过时的年份来说是非常俗气的。
如何在php4或php5中自动更新年份?
当前回答
顺便说一句……网站版权展示有几种合适的方式。有些人倾向于让事情变得多余,例如:版权©具有相同的含义。重要的版权部分包括:
**Symbol, Year, Author/Owner and Rights statement.**
使用PHP + HTML:
<p id='copyright'>© <?php echo date("Y"); ?> Company Name All Rights Reserved</p>
or
<p id='copyright'>© <?php echo "2010-".date("Y"); ?> Company Name All Rights Reserved</p
其他回答
本节的最佳短代码:
<?= date("Y"); ?>
在Laravel
$date = Carbon::now()->format('Y');
return $date;
在PHP中
echo date("Y");
适用于php 5.4+版本
<?php
$current= new \DateTime();
$future = new \DateTime('+ 1 years');
echo $current->format('Y');
//For 4 digit ('Y') for 2 digit ('y')
?>
或者你可以把它用在一行上
$year = (new DateTime)->format("Y");
如果你想增加或减少一年另一个方法;添加修改行如下所示。
<?PHP
$now = new DateTime;
$now->modify('-1 years'); //or +1 or +5 years
echo $now->format('Y');
//and here again For 4 digit ('Y') for 2 digit ('y')
?>
<?php echo date("Y"); ?>
这段代码应该
用M打印当前月份,用D打印日期,用Y打印年份。
<?php echo date("M D Y"); ?>