strototime() 相对日期到时间

strototime() relative dates to the time

目前,我将时区设置为 America/New York

我的时间戳为 1448933400,即 2015 年 11 月 30 日星期一 - 08:30 下午。我想从当前时间戳中获取相对时间作为 "First Sun of Next Month".

所以我正在执行以下代码:

strtotime("First Sun of Next Month", 1448933400);

我遇到的问题是 1449378000 的返回值。

这不是在 8:30 下午,而是在 12:00 上午。有没有一种简单的方法来获取相对日期以保留源时间戳的相对时间?

有很多可能的答案,但您可以先计算时间戳当天的时间偏移量并将其应用于结果:

<?php
$stamp = 1448933400;
$offset = $stamp - strtotime(date("Y-m-d", $stamp));
var_dump(strtotime("First Sun of Next Month", $stamp) + $offset);
?>

输出

int(1449451800) // or "2015-12-06 20:30:00"