首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“strtotime(‘明日’)- time()”或“strtotime(‘明日’)- strtotime('now')”直到午夜才能给出正确的时间。

“strtotime(‘明日’)- time()”或“strtotime(‘明日’)- strtotime('now')”直到午夜才能给出正确的时间。
EN

Stack Overflow用户
提问于 2014-03-13 23:31:22
回答 1查看 3.3K关注 0票数 2

我试着做一个简单的倒计时,但这是错误的时间:

代码语言:javascript
复制
$time_seconds_view = strtotime('tomorrow') - time(); echo date("H" . " \h\o\u\\r\s\, " . "i" . " \m\i\\n\u\\t\\e\s\, \a\\n\d " . "s" . " \s\\e\c\o\\n\d\s", $time_seconds_view);

吐出00 hours, 30 minutes, and 00 seconds

即使date_default_timezone_set($this->session->userdata('timezone'));设置为America/Phoenix

应该是吐出来的07 hours, 30 minutes, and 00 seconds

似乎PHP没有考虑到我已经更改了默认时区。

我做错什么了吗?谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-13 23:49:00

使用DateTime。对约会数学来说要好得多。

代码语言:javascript
复制
$tomorrow = new DateTime('tomorrow');
$now = new DateTime();
$diff = $tomorrow->diff($now);
echo $diff->format("%h hours, %i minutes, %s seconds");
// 7 hours, 12 minutes, 53 seconds

见实际行动

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22393216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档