PHP 获取日期时间的小时差
所以我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将为您提供两个时间戳之间的小时数。
This will give you number of hours between the two timestamps.
这些时间距 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.