Home >Backend Development >PHP Problem >How to convert timestamp to date in php

How to convert timestamp to date in php

王林
王林Original
2020-07-23 14:17:003648browse

The way PHP converts timestamps into dates is through the date() function. The date() function can format a timestamp into a more readable date and time. The specific usage method is: [date('Y-m-s h:i:s',time());].

How to convert timestamp to date in php

Function introduction:

(Recommended tutorial: php tutorial)

PHP date() Function formats a timestamp into a more readable date and time.

Function syntax:

string date( string $format [, int $timestamp])

Parameter description:

  • ##format Required. Specifies the format of the timestamp.

  • #timestamp Optional. Specify timestamp. The default is the current date and time.

Code implementation:

<?php
var_dump(time()); //获取当前时间戳 int(1502245603)
$time = date(&#39;Y-m-s h:i:s&#39;,time());

The above is the detailed content of How to convert timestamp to date in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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