5

明日の真夜中の UNIX タイムスタンプを決定する次のコードがあります。私にはかなりハッキリしているように思えます。誰かがもっとエレガントな解決策を持っているのではないかと思いました。

date("U", strtotime(date("Y-m-d 00:00:00", strtotime("tomorrow"))));
4

1 に答える 1

12

これで十分です:

<?php
$t = strtotime('tomorrow');

時間を設定することもできます:

<?php
$t = strtotime('tomorrow 14:55');

PHP の他の日付機能と同様に、特に要求されない限り、デフォルトのタイム ゾーンが使用されることに注意してください。

date_default_timezone_set('Asia/Tokyo');
$t = strtotime('tomorrow');
var_dump($t, date('r', $t));

date_default_timezone_set('Europe/Madrid');
$t = strtotime('tomorrow');
var_dump($t, date('r', $t));

date_default_timezone_set('Europe/Madrid');
// Generate midnight in New York, display equivalent Madrid time
$t = strtotime('tomorrow America/New_York');
var_dump($t, date('r', $t));
int(1502204400)
string(31) "Wed, 09 Aug 2017 00:00:00 +0900"
int(1502229600)
string(31) "Wed, 09 Aug 2017 00:00:00 +0200"
int(1502251200)
string(31) "Wed, 09 Aug 2017 06:00:00 +0200"
于 2010-03-10T16:53:54.593 に答える