php-比给定的日期时间早一小时 [英] php - One Hour Earlier Than Given Datetime
问题描述
我在这里有问题.
假设我有这种日期时间.
Supposed I have this kind of datetime.
$date = strtotime($date);
我需要将其转换为Unix时间戳格式,但是要早一小时..我尝试了
I need this to be converted into the Unix-timestamp format but one hour earlier..I tried
$date = strtotime($date-86400)
,但是在我看来这是错误的.我潜入桌子时返回0.
, but seemed to me it is wrong. It returned 0 when I sneaked into the table.
实现此目标的合适方法是什么?
What is the appropriate way to achieve this?
谢谢.
推荐答案
strtotime将为您提供日期的unix时间戳.然后从该时间戳记中减去小时:
strtotime will give you the unix timestamp of your date. From this timestamp, you then subtract your hour:
$date = strtotime($date) - 3600; // 3600 = 60 * 60
如果您调用strtotime($date - 3600)
,这就像获取-3600的时间(例如strtotime(-3600)
),这是没有意义的,因为strtotime希望将字符串作为第一个参数.
If you call strtotime($date - 3600)
, it's like obtaining the time for -3600 (e.g. strtotime(-3600)
) which makes no sense because strtotime expects a string as first argument.
这篇关于php-比给定的日期时间早一小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!