How to convert timestamp to year, month, day, hour, minute and second in php

青灯夜游
Release: 2023-03-13 17:26:02
Original
5415 people have browsed it

In PHP, you can use the date() function to convert the timestamp into year, month, day, hour, minute and second. The function of this function is to format the timestamp and convert it into a human-readable time format; syntax "date("Y-m-d H:i:s","timestamp")".

How to convert timestamp to year, month, day, hour, minute and second in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, you can use the date() function To convert the timestamp into year, month, day, hour, minute and second.

The date() function formats the timestamp, converts it to a human-readable time format, and returns the formatted date string.

Example:

<?php
echo date("Y-m-d H:i:s","1635937055");
?>
Copy after login

Output result:

How to convert timestamp to year, month, day, hour, minute and second in php

Description:

  • Y - Year The four-digit representation of

  • y - The two-digit representation of the year

  • m - The numerical representation of the month (from 01 to 12)

  • M - A short text representation of the month (in three letters)

  • n - A numeric representation of the month without leading zeros (1 to 12)

  • h - 12-hour format, with leading zeros (01 to 12)

  • H - 24-hour format, with leading zeros (00 to 23)

  • i - Minutes, with leading zero (00 to 59)

  • s - Seconds, with leading zero (00 To 59)

  • u - Microseconds (new in PHP 5.2.2)

Recommended learning: "PHP Video Tutorial

The above is the detailed content of How to convert timestamp to year, month, day, hour, minute and second in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template