How to convert time zone in PHP?

Guanhui
Release: 2023-03-01 15:28:01
Original
3671 people have browsed it

How to convert time zone in PHP?

How to convert time zone in PHP?

First instantiate the "DateTimeZone" class, and the instantiation parameter is the time zone to be converted; then instantiate the "DateTime" class, whose parameter 1 is the time to be converted, and parameter 2 is the "DateTimeZone" object; Finally, call the format of the "DateTime" object.

Code sample

setTimezone(new DateTimeZone($to));
    return $datetime->format($format);
}
 
$time = changeTimeZone('2018-12-19 00:00:00');
$t = changeTimeZone('2018-12-19 00:00:00', 'Y-m-d');
echo $time;
echo $t;
Copy after login


Recommended tutorial: "PHP"

The above is the detailed content of How to convert time zone in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!