How to Convert UNIX Timestamps to ISO 8601 Formatted Dates in PHP?

Linda Hamilton
Release: 2024-11-14 09:50:02
Original
1035 people have browsed it

How to Convert UNIX Timestamps to ISO 8601 Formatted Dates in PHP?

Convert UNIX Timestamps to ISO 8601 Formatted Dates in PHP

Converting UNIX timestamps into formatted date strings like "2008-07-17T09:24:17Z" in PHP requires a simple technique. To transform a timestamp into this format, follow these steps:

PHP Implementation Using gmdate() Function

The gmdate() function provides a straightforward way to achieve this conversion. It takes a timestamp as an argument and returns a formatted date string according to the specified format. To obtain the ISO 8601 format, use the following syntax:

gmdate("Y-m-d\TH:i:s\Z", $timestamp);
Copy after login

Where:

  • $timestamp is the UNIX timestamp to be converted.
  • "Y-m-dTH:i:sZ" specifies the ISO 8601 format.

Example:

Consider the timestamp 1333699439. Using the gmdate() function, you can convert it to an ISO 8601 string as follows:

$timestamp=1333699439;
echo gmdate("Y-m-d\TH:i:s\Z", $timestamp);
Copy after login

This will output the result: "2008-07-17T09:24:17Z".

The above is the detailed content of How to Convert UNIX Timestamps to ISO 8601 Formatted Dates in PHP?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template