php - 如何通过 strtotime 准确获取当前 UTC 时间?

标签 php utc strtotime

在 PHP 中,如何在不了解托管服务提供商位置的硬编码知识的情况下获取 UTC 的当前时间?

例如,我尝试了以下方法:

time() + strtotime('January 1, 2000')-strtotime('January 1, 2000 UTC')

并发现它报告的时间比实际 UTC 时间早一小时。我在两个不同时区的两个不同托管服务提供商上进行了尝试,结果相同。

是否有可靠(并且希望更清洁)的方法来准确获取 UTC 时间?

我仅限于 PHP 4.4.9,所以我不能使用添加到 PHP5 的新时区内容。

提前致谢。

最佳答案

$time = new DateTime('now', new DateTimeZone('UTC'));
echo $time->format('F j, Y H:i:s');

关于php - 如何通过 strtotime 准确获取当前 UTC 时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1463912/

相关文章:

php - 如何在codeigniter中使用MPDF添加水印图像

php - AWS Elastic Beanstalk - PHP 脚本在部署新版本后无法执行

php - 检查表是否是新创建的或者不在数据库中

java - 对 Instant、ZonedDateTime 和 UTC 感到困惑

c# - 使用 C# 将 UTC 转换为 IST

php - strtotime() 有错误吗?

php strtotime 不起作用

php - 在 python 代码上使用 html

c# - 将 DateTime 转换为 UTC 时的调整规则是什么?

javascript - 如何使用 PHP 存储选定的日期选择器 javascript