我想在一个网站的页脚放一个版权声明,但我认为这对于过时的年份来说是非常俗气的。
如何在php4或php5中自动更新年份?
我想在一个网站的页脚放一个版权声明,但我认为这对于过时的年份来说是非常俗气的。
如何在php4或php5中自动更新年份?
当前回答
对于4位数表示:
<?php echo date('Y'); ?>
2位数表示:
<?php echo date('y'); ?>
查看php文档了解更多信息: https://secure.php.net/manual/en/function.date.php
其他回答
适用于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')
?>
顺便说一句……网站版权展示有几种合适的方式。有些人倾向于让事情变得多余,例如:版权©具有相同的含义。重要的版权部分包括:
**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"); ?>
<?php echo date("Y"); ?>
$dateYear = date('Y');
echo "Current Year: $dateYear";
本年:2022年
$dateYear = date('y');
echo $dateYear;
22