How to Convert UNIX Timestamps to Formatted Date Strings in PHP?

Linda Hamilton
Release: 2024-11-11 11:40:03
Original
1050 people have browsed it

How to Convert UNIX Timestamps to Formatted Date Strings in PHP?

Converting UNIX Timestamps to Formatted Date Strings in PHP

In PHP, the gmdate function can be utilized to convert UNIX timestamps into date strings in a specific format. This function takes two arguments: the date format string and the timestamp to be converted.

To achieve the desired format of "2008-07-17T09:24:17Z", the following date format string can be used: "Y-m-dTH:i:sZ". The Z specifier indicates that the date should be represented in the ISO 8601 format, which includes a "Z" suffix to denote Coordinated Universal Time (UTC).

For example, to convert the timestamp 1333699439 to the desired format, the following code can be used:

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

This code will output the date string "2008-07-17T09:24:17Z", as requested.

The above is the detailed content of How to Convert UNIX Timestamps to Formatted Date Strings 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