如何从日期中找到一个月的最后一天? [英] How to find the last day of the month from date?

查看:27
本文介绍了如何从日期中找到一个月的最后一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 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));

这篇关于如何从日期中找到一个月的最后一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆