在PHP中,是否有一种简单的方法来获取一个月的第一个和最后一个日期? [英] In PHP, is there an easy way to get the first and last date of a month?
本文介绍了在PHP中,是否有一种简单的方法来获取一个月的第一个和最后一个日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只需要给出月份和年份,就需要以YYYY-MM-DD格式获得一个月的第一天和最后一天.有没有一种简便的好方法?
I need to get the first and last day of a month in the format YYYY-MM-DD given only the month and year. Is there a good, easy way to do this?
推荐答案
$first = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year));
$last = date('Y-m-t', mktime(0, 0, 0, $month, 1, $year));
请参见PHP文档中的 date().
See date() in PHP documentation.
这篇关于在PHP中,是否有一种简单的方法来获取一个月的第一个和最后一个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文