小编td-*_*dev的帖子

用PHP减去1天

我正在尝试从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
Run Code Online (Sandbox Code Playgroud)

所以我不明白为什么原始日期对象出来很好,但后来我试图创建一个额外的日期对象并通过减去一天来修改它,似乎我不能那样做.输出总是空白.

php datetimeoffset

71
推荐指数
9
解决办法
19万
查看次数

标签 统计

datetimeoffset ×1

php ×1