我在这里遇到问题..
假设我有这种日期时间.
$date = strtotime($date);
我需要将其转换为Unix时间戳格式,但提前一小时......我试过了
$date = strtotime($date-86400)
,但在我看来这是错误的.当我潜入桌子时,它返回0.
实现这个目标的适当方法是什么?
谢谢.
小智 6
strtotime将为您提供日期的unix时间戳.从这个时间戳,你然后减去你的小时:
$date = strtotime($date) - 3600; // 3600 = 60 * 60
Run Code Online (Sandbox Code Playgroud)
如果你打电话strtotime($date - 3600),就像获得-3600(例如strtotime(-3600))的时间一样没有意义,因为strtotime期望一个字符串作为第一个参数.
你可以这样做:
$testDateStr = strtotime($date);
$finalDate = date("Y-m-d H:i:s", strtotime("-1 hour", $testDateStr));
希望能帮助到你