PHP 获取日期时间的小时差

发布于 2024-08-05 08:48:46 字数 164 浏览 4 评论 0原文

所以我在 PHP 中有这两个时间戳,

1253339331
1253338959

我希望能够以某种方式获得它们与日期时间之间的小时差。我们的用户在第一次尝试后应该只有 24 小时的时间来登录,因此我需要查明是否少于 24 小时以允许他们再次登录。

so I have these two time stamps in PHP

1253339331
1253338959

I want to be able to somehow get the hour difference between those to datetimes. Our users should only have 24 hours to login after their first attempt, so I need to find out if it's less than 24 hours to allow them to login again.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

韶华倾负 2024-08-12 08:48:46
if ((t2-t1)/3600) < 24 { ... }
if ((t2-t1)/3600) < 24 { ... }
靖瑶 2024-08-12 08:48:46
( 1253339331 - 1253338959 ) / ( 60 * 60 )

这将为您提供两个时间戳之间的小时数。

( 1253339331 - 1253338959 ) / ( 60 * 60 )

This will give you number of hours between the two timestamps.

暗藏城府 2024-08-12 08:48:46

这些时间距 1970 年 1 月 1 日仅几秒(参见 Unix 时间);您只需将两者相减,然后除以(60 秒/分钟 * 60 分钟/小时)即可将秒转换为小时。

因此,就您而言,时间间隔仅为 (1253339331-1253338959)/3600 = 0.1 小时。

Those times are just seconds since Jan 1 1970 (see Unix Time); you can just subtract the two, then divide by (60 sec/min * 60 min/hr) to convert the seconds to hours.

So in your case, the times were only (1253339331-1253338959)/3600 = 0.1 hours apart.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文