简体   繁体   中英

Date does not change from UTC PHP

The code below will not give me the time in the timezone I specify. Why

    $dateTimeStr = substr($this->statsGW->fetchLatestDateTime(), 0, -7);
    $defaultTZ = new DateTimeZone("Europe/Rome");
    date_default_timezone_set("Europe/Rome");
    date("H:i",strtotime($dateTimeStr));

Instead it keeps returning the UTC time that is stored in the database and is fetched with the first code.

You need to specify default time zone before get the date.

date_default_timezone_set("Europe/Rome");
$today = getdate();
print_r($today);

You can access any attribute of date object using $today vairable.

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