像“2016年8月”一样,在PHP中显示当前月/年的最简单方法 [英] Simplest way to display current month/year in PHP like "Aug 2016"?
问题描述
在全文中,最简单,最简单的代码就是生成code,$,$,$,C c $ c>然后添加当前年份 2011
What is the shortest, simplest code to generate the curent month in Full English like September
or short as three letter version like Feb
and then add the current Year 2011
所以代码将取决于月和年回覆如下:
So the code will, depending on the month and year, echo things like:
2016年8月
或 2016年8月
etcettera
August 2016
or Aug 2016
etcettera
推荐答案
完整版本:
<? echo date('F Y'); ?>
简短版本:
<? echo date('M Y'); ?>
这是一个不同日期选项的好参考。
更新
要显示上个月,我们将不得不介绍 mktime()函数,并使我们为date()函数的可选 timestamp
参数。如下所示:
To show the previous month we would have to introduce the mktime() function and make us of the optional timestamp
parameter for the date() function. Like this:
echo date('F Y', mktime(0, 0, 0, date('m')-1, 1, date('Y')));
这也将工作(通常用于获取上个月的最后一天): p>
This will also work (it's typically used to get the last day of the previous month):
echo date('F Y', mktime(0, 0, 0, date('m'), 0, date('Y')));
希望有所帮助。
这篇关于像“2016年8月”一样,在PHP中显示当前月/年的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!