最佳答案
我试着从我的 Drupal CMS 中拿出一个日期对象,减去一天,打印出两个日期。这是我手头的资料
$date_raw = $messagenode->field_message_date[0]['value'];
print($date_raw);
//this gives me the following string: 2011-04-24T00:00:00
$date_object = date_create($date_raw);
$next_date_object = date_modify($date_object,'-1 day');
print('First Date ' . date_format($date_object,'Y-m-d'));
//this gives me the correctly formatted string '2011-04-24'
print('Next Date ' . date_format($next_date_object,'Y-m-d'));
//this gives me nothing. The output here is always blank
所以我不明白为什么原始的日期对象出来的很好,但然后我试图创建一个额外的日期对象,并通过减去一天来修改它,似乎我不能这样做。输出总是空白的。