如何在 php 中找到第二天开始的 unix 时间戳?
我有一个当前时间的 unix 时间戳。我想获取第二天开始的 unix 时间戳。
$current_timestamp = time();
$allowable_start_date = strtotime('+1 day', $current_timestamp);
正如我现在所做的那样,我只是将 1 整天添加到 unix 时间戳中,而我想知道当天还剩多少秒,并且只添加那么多秒以获得 unix 时间戳第二天第一分钟的时间戳。
解决这个问题的最佳方法是什么?
I have a unix timestamp for the current time. I want to get the unix timestamp for the start of the next day.
$current_timestamp = time();
$allowable_start_date = strtotime('+1 day', $current_timestamp);
As I am doing it now, I am simply adding 1 whole entire day to the unix timestamp, when instead I would like to figure out how many seconds are left in this current day, and only add that many seconds in order to get the unix timestamp for the very first minute of the next day.
What is the best way to go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
最直接的方法是简单地“make”
:
不要那样做。尽可能避免相对计算,特别是如果在没有秒算术的情况下“绝对”获取时间戳是如此微不足道。
The most straightforward way to simply "make" that time:
Quote:
Don't do it like that. Avoid relative calculations whenever possible, especially if it's so trivial to "absolutely" get the timestamp without seconds arithmetics.
您可以轻松地获得明天的午夜时间戳:
如果您希望能够执行可变的天数,您可以轻松地这样做:
You can easily get tomorrow at midnight timestamp with:
If you want to be able to do a variable amount of days you could easily do it like so:
像这样简单的东西:
就是我会用的。
Something simple like:
is what I'd use.
第二天的开始时间是这样计算的:
如果需要遵循您的特殊要求:
The start of the next day is calculated like this:
If it needs to follow your peculiar requirement:
我的变体:
My variant: