php 获取下个月的第一天

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13422032/
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 05:22:53  来源:igfitidea点击:

Get 1st day of next month

phpdatetimestamp

提问by Carlos Martins

Possible Duplicate:
how to find first day of the next month and remain days to this date with php

可能的重复:
如何使用 php 查找下个月的第一天并保留到该日期的天数

I have this to get 1st day of current month

我有这个来获得当月的第一天

$_SERVER['dataInicio'] = date('Y') . "-" . date('m') . "-" . "1";

I need something similar to get 1st day of NEXT month

我需要类似的东西来获得下个月的第一天

采纳答案by Clark T.

This seems like a duplicate or similar post to this for the next month

这似乎是下个月的重复或类似帖子

but for the next month something like this if you want to use strtotime

但是对于下个月,如果你想使用 strtotime

date("m/l/Y", strtotime(date('m', strtotime('+1 month')).'/01/'.date('Y').' 00:00:00'));

this will return

这将返回

12/Saturday/2012 if you want just the days name just set the date format to l (lower case L)

12/Saturday/2012 如果您只需要日期名称,只需将日期格式设置为 l(小写 L)

date("l", strtotime(date('m', strtotime('+1 month')).'/01/'.date('Y').' 00:00:00'));

date("l", strtotime(date('m', strtotime('+1 month')).'/01/'.date('Y').' 00:00:00'));

How to find first day of the next month and remaining days till this date with PHP

如何使用PHP查找下个月的第一天和直到该日期的剩余天数

or this

或这个

In PHP, is there an easy way to get the first and last date of a month?

在 PHP 中,有没有一种简单的方法来获取一个月的第一个和最后一个日期?

回答by rscata

$date = new DateTime('now');

$date->modify('first day of next month');
echo $date->format('D') . '\n';

$date->modify('first day of this month');
echo $date->format('D') . '\n';

回答by Benny Hill

$_SERVER['dataInicio'] = date('Y-m-d', mktime(0, 0, 0, date('m')+1, 1, date('Y')));

Should do what you're wanting.

应该做你想做的。