作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
哪个 PHP 函数可以返回当前日期/时间?
最佳答案
时间将按您的服务器时间计算。一个简单的解决方法是使用 date_default_timezone_set
手动设置时区。在 date()
之前或 time()
调用函数。
我在墨尔本,Australia所以我有这样的事情:
date_default_timezone_set('Australia/Melbourne');
或者另一个例子是洛杉矶 - US :
date_default_timezone_set('America/Los_Angeles');
您还可以通过以下方式查看服务器当前所在的时区:
date_default_timezone_get();
比如:
$timezone = date_default_timezone_get();
echo "The current server timezone is: " . $timezone;
所以你的问题的简短答案是:
// Change the line below to your timezone!
date_default_timezone_set('Australia/Melbourne');
$date = date('m/d/Y h:i:s a', time());
那么所有时间都将是您刚刚设置的时区:)
关于php - 如何在 PHP 中获取当前日期和时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/470617/
我是一名优秀的程序员,十分优秀!