Home >Backend Development >PHP Tutorial >How to Obtain UTC Time Stamps with Time Zone Offset in PHP?
When attempting to retrieve time stamps in PHP using date(), by default, Unix time stamps are returned. However, what if you need to obtain UTC/GMT time stamps with time zone offset information?
To get UTC/GMT time stamps, including time zone offsets, you can utilize the gmdate() function. The syntax is similar to date():
<code class="php">gmdate("Y-m-d H:i:s \G\M\T/UTC\P");</code>
This expression will return a time stamp in the format YYYY-MM-DD HH:MM:SS GMT/UTC±0000, where the offset is adjusted based on your local time zone settings.
For instance, if your local time zone is 4 hours behind UTC, it will output:
2023-03-08 14:30:00 GMT/UTC-0400
Alternatively, if your local time zone is 10 hours ahead of UTC, the result would be:
2023-03-08 14:30:00 GMT/UTC+1000
To illustrate the usage of gmdate(), consider the following code snippet:
<code class="php"><?php echo "Current UTC time with time zone offset:\n"; echo gmdate("Y-m-d H:i:s \G\M\T/UTC\P"); ?></code>
Output:
Current UTC time with time zone offset: 2023-03-08 14:30:00 GMT/UTC-0400
The above is the detailed content of How to Obtain UTC Time Stamps with Time Zone Offset in PHP?. For more information, please follow other related articles on the PHP Chinese website!