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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:57:23  来源:igfitidea点击:

How to get last day of the month using php

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 trepresents 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 tmeans the last date of the current month.

其中t表示当月的最后一天。

PHP: date - Manual

PHP: 日期 - 手册

How can I find the first and last date in a month using PHP?

如何使用PHP查找一个月中的第一个和最后一个日期?

回答by MISJHA

Using the function dateyou 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'))
);