Skip to main content

๐ŸŽ Timezone

zjkalLess than 1 minute

๐ŸŽ Timezone

Tips

It mainly provides a way to get the time of different time zones and convert the time of different time zones

timezoneFormat()

Time zone conversion

Parameters

ParameterIntroductionRequire
toTimezoneTarget time zonerequired
fromTimezoneOriginal time zoneOptional, the default is the time zone set by the current PHP runtime environment
datetimeany type of string time or timestampOptional, defaults to the current time
formatThe date format is the same as that of the system function date().Optional, default is Y-m-d H:i:s

Return Values

The return value is a time string for the target time zone

Example code

/* Convert a specified time in the China time zone to London time */
TimeHelper::timezoneFormat('Europe/London', 'Asia/Shanghai', '2023-8-5 19:16:43', 'H:i:s');
// 11:16:43

/* Get the current time in Los Angeles */
TimeHelper::timezoneFormat('America/Los_Angeles');
// 04:16:43

/* Convert timestamps to London time */
TimeHelper::timezoneFormat('Europe/London', null, 1692097543);
// 11:19:03

Info

For a list of supported time zones, refer to List of PHP Supported Time Zonesopen in new window