Ben*_*ath 5 php unix-timestamp
我有以下代码来确定明天午夜的unix时间戳.对我来说这看起来很漂亮,我想知道是否有人有更优雅的解决方案.
date("U", strtotime(date("Y-m-d 00:00:00", strtotime("tomorrow"))));
Run Code Online (Sandbox Code Playgroud)
Álv*_*lez 12
这应该足够了:
<?php
$t = strtotime('tomorrow');
Run Code Online (Sandbox Code Playgroud)
你也可以设定一个时间:
<?php
$t = strtotime('tomorrow 14:55');
Run Code Online (Sandbox Code Playgroud)
请注意,与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));
Run Code Online (Sandbox Code Playgroud)
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"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7088 次 |
| 最近记录: |