代码在线时,DateTime函数出现错误

时间:2019-07-14 12:38:20

标签: php datetime

我正在使用以下代码设置时区。

public function getDate()
    {
        $timezone = new DateTimeZone("Asia/Kolkata");
        $datetime = new DateTime();
        $datetime->setTimezone($timezone);
        return $datetime->format('Y-m-d H:i:s');
    }

它在localhost上运行良好,但是当它联机时,它向我显示以下错误

Uncaught exception 'Exception' with message 'DateTime::__construct(): 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.' in /home/

0 个答案:

没有答案