Home > Article > Backend Development > How to Get UTC Timestamps with Timezone Offset in PHP?
Obtaining UTC Timestamps in PHP with gmdate
To retrieve a UTC/GMT timestamp with a specified timezone offset in PHP, you can utilize the gmdate() function. Unlike date() which provides timestamps based on the local timezone, gmdate() consistently outputs timestamps in UTC.
The syntax of gmdate() is analogous to that of date():
<code class="php">gmdate(format, timestamp);</code>
Where:
Example:
To obtain a UTC timestamp in the format "YYYY-MM-DD HH:MM:SS" with the timezone offset "GMT/UTC 0400":
<code class="php">echo gmdate("Y-m-d H:i:s") . " GMT/UTC+0400";</code>
This will print the current UTC timestamp with the specified timezone offset appended.
The above is the detailed content of How to Get UTC Timestamps with Timezone Offset in PHP?. For more information, please follow other related articles on the PHP Chinese website!