我正在尝试获取一个从我的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
我不明白为什么原始日期对象正常显示,但是当我尝试创建一个额外的日期对象并通过减去一天来修改它时,似乎我无法这样做。输出总是空白。
$date_raw = date("r");
获取与$date_raw
相同的格式。 - sHaDeoNeRDateTime
(请参见此处)。 - Tip-Sy