PHP偏移unix时间戳

Jus*_*tin 2 php timezone datetime unix-timestamp

我有一个 Unix 时间戳PHP

$timestamp = 1346300336;
Run Code Online (Sandbox Code Playgroud)

然后我有一个我想要应用的时区的偏移量。基本上,我想应用偏移量并返回一个新的 unix 时间戳。偏移量遵循这种格式,不幸的是,由于与其他代码兼容,无法更改:

$offset_example_1 = "-07:00";
$offset_example_2 = "+00:00";
$offset_example_3 = "+07:00";
Run Code Online (Sandbox Code Playgroud)

我试过:

$new_timestamp = strtotime($timestamp . " " . $offset_example_1);
Run Code Online (Sandbox Code Playgroud)

但是,这并没有不幸的是工作:(。任何其他的想法?

编辑

测试后,我超级惊讶,但即使这样也行不通:

strtotime("1346300336 -7 hours")
Run Code Online (Sandbox Code Playgroud)

返回假。

让我们用不同的方式处理这个问题,将上面的偏移示例转换为秒的最佳方法是什么?然后我可以简单地做$timestamp + $timezone_offset_seconds

xda*_*azz 5

您应该将原始时间戳作为第二个参数传递给strtotime.

$new_timestamp = strtotime("-7 hours", $timestamp);
Run Code Online (Sandbox Code Playgroud)