如何从日期中找到一个月的最后一天?

问题描述:

如何在 PHP 中获取本月的最后一天?

How can I get the last day of the month in PHP?

给定:

$a_date = "2009-11-23"

我要 2009-11-30;并给出

I want 2009-11-30; and given

$a_date = "2009-12-23"

我想要 2009-12-31.

I want 2009-12-31.

t 返回给定日期的月份中的天数(请参阅 date 的文档):

t returns the number of days in the month of a given date (see the docs for date):

$a_date = "2009-11-23";
echo date("Y-m-t", strtotime($a_date));