Php 增加2小时的发布时间

Php 增加2小时的发布时间,php,time,Php,Time,我如何在这篇文章的时间上增加2小时 $config['post_date'] = '%d/%m/%y (%a) %H:%M:%S'; 我尝试过切换时区,但它没有改变任何东西,所以我只想手动添加2小时。首先,您需要创建一个对象: 然后您可以使用: 最后,您可以使用设置日期格式: $date->format('Y-m-d H:i:s'); 编辑: 在您的特定情况下,代码如下所示: $config = array('post_date' => '21/06/14 (Sat) 14:00

我如何在这篇文章的时间上增加2小时

$config['post_date'] = '%d/%m/%y (%a) %H:%M:%S';

我尝试过切换时区,但它没有改变任何东西,所以我只想手动添加2小时。

首先,您需要创建一个对象:

然后您可以使用:

最后,您可以使用设置日期格式:

$date->format('Y-m-d H:i:s');
编辑:

在您的特定情况下,代码如下所示:

$config = array('post_date' => '21/06/14 (Sat) 14:00:00');

$date = DateTime::createFromFormat('d/m/y (D) H:i:s', $config['post_date']);
$date->modify('+2 hours');
$config['post_date'] = $date->format('d/m/y (D) H:i:s');

您不能直接使用
strftime
格式添加
2小时
。首先将其转换为时间戳,添加小时数,然后输入格式和时间戳。考虑这个例子:

$date = strtotime('+2 hours', time());
$config['post_date'] = '%d/%m/%y (%a) %H:%M:%S'; // strftime format
$config['post_date'] = strftime($config['post_date'], $date);
echo strftime('%d/%m/%y (%a) %H:%M:%S') . '<br/>';
echo $config['post_date'];

这对我的“后约会”有什么影响?它没有影响它。@user3762728更新了我的答案。
$config = array('post_date' => '21/06/14 (Sat) 14:00:00');

$date = DateTime::createFromFormat('d/m/y (D) H:i:s', $config['post_date']);
$date->modify('+2 hours');
$config['post_date'] = $date->format('d/m/y (D) H:i:s');
$date = strtotime('+2 hours', time());
$config['post_date'] = '%d/%m/%y (%a) %H:%M:%S'; // strftime format
$config['post_date'] = strftime($config['post_date'], $date);
echo strftime('%d/%m/%y (%a) %H:%M:%S') . '<br/>';
echo $config['post_date'];
21/06/14 (Sat) 19:59:59
21/06/14 (Sat) 21:59:59