简体   繁体   中英

Change date time to UTC FORMAT

I need to rewrite date time format from zendframework to codeigniter

Here is Zendframe work UTC format function

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');
}

Here is my code for 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');

But I didn't get same date result.

Try setting your default time zone as UTC

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

You can also use gmdate , see here for more reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM