gpt4 book ai didi

php - 如何在 PHP 中使用 date_default_timezone_set() 函数和 +1 天的日期

转载 作者:行者123 更新时间:2023-11-29 12:38:12 25 4
gpt4 key购买 nike

我有一个输入一组日期的表单,这些日期将用于 mysql 查询。与 mysql 查询一起使用时,日期必须是 $date +1 天。它工作正常,除了服务器返回有关使用 date_default_timezone_set() 的警告。

//$date is date captured from an input form
$selected_date = date("Y-m-d", strtotime($date . "+1 days"));

收到错误消息

Warning: strtotime(): It is not safe to rely on the system's timezone settings.
You are required to use the date.timezone setting or the date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning,
you most likely misspelled the timezone identifier.
We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.

如何使用 date_default_timezone_set() 函数并在所选日期中添加一天?

最佳答案

您可以通过添加一行来设置默认 utc 时区。由于系统时间可能会有所不同,您可以定义默认 utc 时间并创建或编辑日期

 date_default_timezone_set('UTC');
$selected_date = date("Y-m-d", strtotime($date . "+1 days"));

关于php - 如何在 PHP 中使用 date_default_timezone_set() 函数和 +1 天的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26458744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com