zec*_*ude 18 php unix-timestamp
我有一个当前时间的unix时间戳.我想获得第二天开始的unix时间戳.
$current_timestamp = time();
$allowable_start_date = strtotime('+1 day', $current_timestamp);
Run Code Online (Sandbox Code Playgroud)
正如我现在所做的那样,我只是将整整一天添加到unix时间戳中,相反,我想知道在当前这一天剩下多少秒,并且只添加那么多秒才能获得unix第二天第一分钟的时间戳.
最好的方法是什么?
dec*_*eze 26
简单地" 制造 "那个时间的最简单的方法:
$tomorrowMidnight = mktime(0, 0, 0, date('n'), date('j') + 1);
Run Code Online (Sandbox Code Playgroud)
引用:
我想弄清楚当天剩下多少秒,并且只添加那么多秒才能获得第二天第一分钟的unix时间戳.
不要那样做.尽可能避免相对计算,特别是如果在没有秒算术的情况下"绝对"获得时间戳是如此微不足道.
小智 8
您可以在午夜时间戳中轻松获得:
$tomorrow_timestamp = strtotime('tomorrow');
Run Code Online (Sandbox Code Playgroud)
如果您希望能够执行可变天数,则可以轻松地执行此操作:
$days = 4;
$x_num_days_timestamp = strtotime(date('m/d/Y', strtotime("+$days days"))));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23060 次 |
| 最近记录: |