如何在php中找到第二天开始的unix时间戳? [英] How do I find the unix timestamp for the start of the next day in php?

查看:41
本文介绍了如何在php中找到第二天开始的unix时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个当前时间的 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);

正如我现在所做的那样,我只是在 unix 时间戳中添加一整天的时间,而我想弄清楚这一天还剩多少秒,并且只添加那么多秒以便获取第二天第一分钟的 Unix 时间戳.

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?

推荐答案

最简单的make 方法" 那个时候:

The most straightforward way to simply "make" that time:

$tomorrowMidnight = mktime(0, 0, 0, date('n'), date('j') + 1);

引用:

我想算出这一天还剩多少秒,并且只添加那么多秒以获得第二天第一分钟的 unix 时间戳.

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.

不要那样做.尽可能避免相对计算,尤其是在没有秒算术的情况下绝对"获取时间戳是如此微不足道的情况下.

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.

这篇关于如何在php中找到第二天开始的unix时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆