php 如何在php中获得当月的第一天?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16641924/
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 11:29:55 来源:igfitidea点击:
How to get first day of current month in php?
提问by Oscar
What I want to do is get 1st date of current month
我想要做的是获得当月的第一个日期
Here is how to get last day of the current month
这是获取当月最后一天的方法
date('d-m-Y', strtotime('last day of this month'))
I've tried to use this, but it didn't work for me
我试过使用这个,但它对我不起作用
date('d-m-Y', strtotime('first day of this month'))
Any idea how to solve my problem ?
知道如何解决我的问题吗?
回答by Niet the Dark Absol
date('01-m-Y')
should do it ;)
date('01-m-Y')
应该这样做;)
回答by zerkms
date('d-m-Y', strtotime(date('Y-m-1')));
回答by Andrey Zarovnyaev
$firstDayUTS = mktime (0, 0, 0, date("m"), 1, date("Y"));
$lastDayUTS = mktime (0, 0, 0, date("m"), date('t'), date("Y"));
$firstDay = date("d-m-Y", $firstDayUTS);
$lastDay = date("d-m-Y", $lastDayUTS);
回答by Raptor
How about :
怎么样 :
date('1-m-Y',strtotime('this month'));