Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

php - 如何使用PHP获取当前年份?(How do I use PHP to get the current year?)

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 ?

(如何使用PHP 4PHP 5自动更新年份?)

  ask by JD Graffam translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use either date or strftime .

(您可以使用datestrftime 。)

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.

(另外,在PHP格式化日期时,如果要将日期格式设置为与默认语言不同的语言环境,则这很重要。)

If so, you have to use setlocale and strftime.

(如果是这样,您必须使用setlocale和strftime。)

According to the php manual on date:

(根据日期的php手册 :)

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

(要格式化其他语言的日期,您应该使用setlocale()和strftime()函数而不是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.

(从这个角度来看,我认为最好尽可能使用strftime,如果你甚至有可能无法本地化你的应用程序。)

If that's not an issue, pick the one you like best.

(如果这不是问题,请选择您最喜欢的那个。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...