20

現在の時刻のUNIXタイムスタンプがあります。翌日の開始のUNIXタイムスタンプを取得したい。

$current_timestamp = time();
$allowable_start_date = strtotime('+1 day', $current_timestamp);

私は今それを行っているので、UNIXタイムスタンプに丸1日を追加するだけです。代わりに、この日の残り秒数を計算し、UNIXを取得するためにその秒数だけを追加します。翌日の最初の1分間のタイムスタンプ。

これを行うための最良の方法は何ですか?

4

6 に答える 6

28

その時間を単純に「作る」ための最も簡単な方法:

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

引用:

この日の残り秒数を把握し、その秒数を追加するだけで、翌日の最初の1分間のUNIXタイムスタンプを取得したいと思います。

そのようにしないでください。特に、秒の計算なしでタイムスタンプを「絶対に」取得するのが非常に簡単な場合は、可能な限り相対的な計算を避けてください。

于 2010-03-26T08:20:46.897 に答える
10

次の方法で、明日の深夜のタイムスタンプを簡単に取得できます。

$tomorrow_timestamp = strtotime('tomorrow');

さまざまな日数を実行できるようにしたい場合は、次のように簡単に実行できます。

$days = 4;
$x_num_days_timestamp = strtotime(date('m/d/Y', strtotime("+$days days"))));
于 2010-03-26T08:04:14.777 に答える
4
$tomorrow = strtotime('+1 day', strtotime(date('Y-m-d')));
$secondsLeftToday = time() - $tomorrow;
于 2010-03-26T00:26:50.890 に答える
1

次のような単純なもの:

$nextday = $current_timestamp + 86400 - ($current_timestamp % 86400);

私が使用するものです。

于 2010-03-26T00:26:20.843 に答える
0

翌日の開始は次のように計算されます。

<?php

$current_timestamp = time();
$allowable_start_date = strtotime('tomorrow', $current_timestamp);

echo date('r', $allowable_start_date);

?>

固有の要件に従う必要がある場合:

<?php

$current_timestamp = time();
$seconds_to_add = strtotime('tomorrow', $current_timestamp) - $current_timestamp;

echo date('r', $current_timestamp + $seconds_to_add);

?>
于 2010-03-26T08:56:46.167 に答える
0

私の変種:

 $allowable_start_date = strtotime('today +1 day');
于 2013-12-04T09:58:29.680 に答える