Home >Backend Development >PHP Problem >What is timestamp in php?

What is timestamp in php?

青灯夜游
青灯夜游Original
2019-10-17 16:33:143105browse

What is timestamp in php?

What is a timestamp in php?

The timestamp refers to the total number of seconds from 00:00:00 on January 1, 1970, Greenwich Time (08:00:00 on January 1, 1970, Beijing time) to the present Number of seconds. It is also called Unix Timestamp.

PHP About timestamps, the use of time

1. Get timestamp

time();     // 1571299936

2.date(), format a local time/ Date

The time obtained using date() is related to the time zone.

In the following example, Beijing time is obtained:

date('Y-m-d H:i:s', time());     // 2019-10-17 10:12:36

3. gmdate(), format a GMT/UTC date/time

Same as date() Usage: The time returned has nothing to do with the time zone. The time returned is Greenwich Mean Time (GMT).

gmdate('Y-m-d H:i:s', time());     // 2019-10-17 10:12:42

4. strtotime(): Parse the date and time description of any English text into a timestamp.

Used to convert the date represented by the English text string into a timestamp. It is the inverse function of date(). It returns the timestamp successfully, otherwise it returns FALSE.

<?php
echo strtotime("2009-10-21 16:00:10");  //输出 1256112010
echo strtotime("10 September 2008");    //输出 1220976000
echo strtotime("+1 day"), "<br />";   //输出明天此时的时间戳
?>

5. mktime(): Get the timestamp from the date and return the timestamp successfully, otherwise return FALSE.

<?php
echo mktime(21, 50, 55, 07, 14, 2010);      //输出“1279115455”
?>

For more PHP related knowledge, please visit php中文网!

The above is the detailed content of What is timestamp 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