Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将日期时间更改为UTC格式_Php_Codeigniter_Zend Framework - Fatal编程技术网

Php 将日期时间更改为UTC格式

Php 将日期时间更改为UTC格式,php,codeigniter,zend-framework,Php,Codeigniter,Zend Framework,我需要将zendframework中的日期时间格式重写为codeigniter 下面是Zendframe工作UTC格式函数 function _dayToDateTime($day, $begin = true) { $oDate = new Date($day); if (!$begin) { $oDate->setHour(23); $oDate->setMinute(59); $oDate->setSecon

我需要将zendframework中的日期时间格式重写为codeigniter

下面是Zendframe工作UTC格式函数

function _dayToDateTime($day, $begin = true)
{
    $oDate = new Date($day);
    if (!$begin) {
        $oDate->setHour(23);
        $oDate->setMinute(59);
        $oDate->setSecond(59);
    }
    $oDate->toUTC();

    return $oDate->format('%Y-%m-%d %H:%M:%S');
}
这是我的codeigniter代码

$timeZone = new DateTimeZone('UTC');
$dt = new DateTime($from_date,$timeZone);
$dt->setTime(23, 59, 59);
echo $format=$dt->format('Y-m-d H:i:s');

但我没有得到相同的日期结果。

尝试将默认时区设置为
UTC

date_default_timezone_set("UTC");
echo date("Y-m-d H:i:s", time()); 

您也可以使用
gmdate
,有关更多参考信息,请参阅。

尝试将默认时区设置为
UTC

date_default_timezone_set("UTC");
echo date("Y-m-d H:i:s", time()); 
您也可以使用
gmdate
,有关更多参考,请参阅