PHP 只得到月份需要完整的时间戳
PHP Only got month need whole timestamp
我从一个数组中得到了一个月份数字并将其放入一个变量中。
现在我想用月份在月初或月底制作整个日期戳。
但是对于我来说,我不知道该怎么做。
$startmonth = date("m", strtotime($date[1]));
$endmonth= date("m", strtotime($date[3]));
startdate 变量应该是这样的:2015-06-01
enddate 变量应该是这样的:2015-07-30
$startmonth = date("Y-m-01", strtotime($date[1]));
$endmonth = date("Y-m-d", strtotime("last day of this month", strtotime($date[3])));
月初很简单:始终为“01”,因此请按照您的格式进行编码。
一个月的最后一天更难。幸运的是 PHP 的 strtotime
允许大量的日期操作。请参阅 HERE.
处的文档
我从一个数组中得到了一个月份数字并将其放入一个变量中。
现在我想用月份在月初或月底制作整个日期戳。
但是对于我来说,我不知道该怎么做。
$startmonth = date("m", strtotime($date[1]));
$endmonth= date("m", strtotime($date[3]));
startdate 变量应该是这样的:2015-06-01
enddate 变量应该是这样的:2015-07-30
$startmonth = date("Y-m-01", strtotime($date[1]));
$endmonth = date("Y-m-d", strtotime("last day of this month", strtotime($date[3])));
月初很简单:始终为“01”,因此请按照您的格式进行编码。
一个月的最后一天更难。幸运的是 PHP 的 strtotime
允许大量的日期操作。请参阅 HERE.