确定月份长度和第一天
有没有一种简单的方法,给定一个月和一年,确定:
该月有多少天(考虑闰年)完成- 第一天是一周中的哪一天?
Is there a simple way of, given a month and a year, establishing:
How many days there are in that month (factoring in leap years)Done- What day of the week the first day fall upon?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅http://php.net/manual/en/function。 cal-days-in-month.php
和 weekdays:
后者效率不是很高,但似乎比使用 getdate 更好:
输出如下
See http://php.net/manual/en/function.cal-days-in-month.php
and weekdays:
The latter is not very efficient but seems nicer than using getdate:
Output like
您可以通过访问维基百科找到问题的答案以及所有所需的变量和计算。 http://en.wikipedia.org/wiki/Calculate_the_day_of_the_week
You may find the answer to your questions with all needed variables and calculations by going to wikipedia. http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week
看一下
date
函数,特别是 < code>date('t') 表示该月的天数(即time()
中给出的月份)和date('t',$epoch)
为时间戳表示的月份的天数$epoch
(当然,是以纪元给出的)。对于星期几,有
date('l',$epoch)
(其中第一个参数是小写的'L'
)。Take a look at the
date
function, particularlydate('t')
for the number of days in the month (ie the month given intime()
) anddate('t',$epoch)
for the number of days of the month represented by the timestamp$epoch
(which, of course, is given in epoch).And for the day of the week, there's
date('l',$epoch)
(where the first argument is a lower-case'L'
).