如何使用PHP获取当前年份? [英] How do I use PHP to get the current year?

查看:96
本文介绍了如何使用PHP获取当前年份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把一个版权声明放在一个网站的页脚,但我认为这个年份是不合时宜的。如何使用 PHP  4 PHP 5

解决方案

您可以使用 date strftime 。在这种情况下,我会说这不重要,因为一年是一年,无论什么(除非有一个不同格式的地区)。



示例:

 <?php echo date(Y); ?> 

在旁注中,当在PHP中格式化日期时,您需要在不同于您默认的区域。如果是这样,你必须使用setlocale和strftime。根据日期的 php手册


为了格式化其他语言的日期,
你应该使用setlocale()和
strftime()函数,而不是
date()。


从这个角度来看,我认为最好尽可能使用strftime,如果你甚至有一个远程的可能性必须本地化您的应用程序。如果这不是问题,请选择你最喜欢的一个。


I want to put a copyright notice in the footer of a web site, but I think it's incredibly tacky for the year to be out-of-date. How would I make the year update automatically with PHP 4 and PHP 5?

解决方案

You can use either date or strftime. In this case I'd say it doesn't matter as a year is a year, no matter what (unless there's a locale that formats the year differently?)

For example:

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

On a side note, when formatting dates in PHP it matters when you want to format your date in a different locale than your default. If so, you have to use setlocale and strftime. According to the php manual on date:

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

From this point of view, I think it would be best to use strftime as much as possible, if you even have a remote possibility of having to localize your application. If that's not an issue, pick the one you like best.

这篇关于如何使用PHP获取当前年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆