2012-11-16 72 views

回答

3

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

但下个月这样的事情,如果你想的strtotime

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

使用这将返回

12 /星期六/ 2012,如果你只想日子名刚刚设置的日期格式为L(L的小写)

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

或本

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

+1

我会这样做,而不是在12月。 strtotime(date('m',strtotime('+ 1 month'))。'/ 01 /'。date('Y',strtotime('+ 1 month'))); – Halfstop

+0

@Halfstop伟大的一点,我会更新我的答案 –

+0

我运行此代码在2017年 - DEC-15和它的返回01 /星期日/ 2017年,所以它来到我12个月后它不会让我移动到2018年。所以这种技术不给正确的输出。 我找到了一个解决方案: $ date_obj = date_create(“下个月的第一天”); echo $ date = date_format($ date_obj,“Y-m-d H:i:s”); –

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

应该做你想要什么。

+0

2012年12月下个月的第一天应该是2013-1-1 –

+1

@CarlosMartins - 代码适用于任何月份。请参阅mktime文档:http://php.net/manual/en/function.mktime.php –

14
$d = new DateTime("now"); 

$d->modify('first day of next month'); 
echo $d->format('D'), "\n"; 

$d->modify('first day of this month'); 
echo $d->format('D'), "\n"; 
+1

看起来不错,但是如果您向代码添加一些评论,那么理解您的提案将会更加有帮助。 – Yaroslav

+2

最简单的方法:$ firstDayNextMonth = date('Y-m-d',strtotime('下个月的第一天')); – pollux1er

相关问题