php 如何使用php获取本月的最后一天
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16351396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get last day of the month using php
提问by jems peterson
How to get last day of the month using php ?
如何使用php获取本月的最后一天?
<?php
echo date('?-?-?');
?>
采纳答案by Mayur Patel
<?php
$day=new DateTime('last day of this month');
echo $day->format('M jS');
?>
回答by hjpotter92
The date function documentationsays that t
represents number of days in current month:
该日期函数文档说,t
代表当月的天数:
$day = date( 't-m-Y' );
回答by Yogesh Suthar
try this
尝试这个
$day=date('Y-m-t'); // gives last day of current month
OR
或者
$d = new DateTime( '2013-05-03' );
echo $d->format( 'Y-m-t' );
回答by hsuk
Try:
尝试:
$last_day = date('t-m-Y');
where t
means the last date of the current month.
其中t
表示当月的最后一天。
How can I find the first and last date in a month using PHP?
回答by MISJHA
Using the function date
you would do
使用date
你会做的功能
$day = date("t");
Please read the documentation
请阅读文档
回答by Santosh Panda
Try this
尝试这个
$date = new DateTime();
$lastDayOfMonth = $date->modify(
sprintf('+%d days', $date->format('t') - $date->format('j'))
);