Php 如何在0点00分获得约会?

Php 如何在0点00分获得约会?,php,Php,我想得到30天前的日期: $one_month_ago = date_create("now"); date_sub($one_month_ago, date_interval_create_from_date_string('30 days')); 我希望一个月前的小时部分、分钟部分和秒部分都为0。怎么做 //on 2020-11-26 15:26 $midnight30daysAgo = date_create('-30 days 00:00:00'); var_dum

我想得到30天前的日期:

$one_month_ago = date_create("now");
date_sub($one_month_ago, date_interval_create_from_date_string('30 days'));
我希望
一个月前
的小时部分、分钟部分和秒部分都为0。怎么做

//on 2020-11-26 15:26
$midnight30daysAgo = date_create('-30 days 00:00:00');
var_dump($midnight30daysAgo);
输出:

object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "2020-10-27 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(13) "Europe/Berlin"
}
object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2020-10-26 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(13) "Europe/Berlin"
}
减去一个月:

$one_month_ago = date_create('-1 month 00:00:00');
var_dump($one_month_ago);
输出:

object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "2020-10-27 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(13) "Europe/Berlin"
}
object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2020-10-26 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(13) "Europe/Berlin"
}

注意:由于PHP中的错误/不一致性,在月底可能会导致意外的结果,方法是通过添加/减去月份

Pass
today
而不是
now
。如何知道要在
date\u create
中输入的关键字?下面是一个完整的示例。