PHP gets the last modification time of the current page. We can achieve this through the date and getlastmod functions in PHP.
Let's use a simple code example to introduce to you the implementation method of getting the last modification time of the page in PHP.
The code example is as follows:
<?php echo "最后一次修改的时间为:" . date ("Y-m-d H:i:s.", getlastmod())."\n";
The output result is as follows:
Here we get the last modified time of the current page: 2019- 01-25 10:55:13.
Main function introduction:
date() function is used to format a local time/date
date ( string $format [, int $timestamp ] ) : string
returns The integer timestamp is a string generated according to the given format string. If no timestamp is given, the local current time is used. In other words, timestamp is optional and the default value is time().
Since PHP 5.1.1 there are several useful constants that can be used as standard date/time formats to specify the format parameter. The timestamp of the time when the request was initiated is stored in $_SERVER['REQUEST_TIME'].
Note: The typical range of valid timestamps is December 13, 1901 20:45:54 GMT to January 19, 2038 03:14:07 GMT. (This range conforms to the minimum and maximum values of 32-bit signed integers). However, prior to PHP 5.1 this range was limited to January 1, 1970 to January 19, 2038 on some systems such as Windows.
getlastmod() function is used to get the last modification time of the page.
getlastmod ( void ) : int
Get the last modification time of the executed main script.
Return value, returns the last modified time of the current page. This value is a Unix timestamp that can be passed into date(). Returns FALSE on error.
This article is an introduction to the method of getting the last modification time of the current page in PHP. It is very simple and easy to understand. I hope it will be helpful to friends in need!
The above is the detailed content of How to get the last modification time of the current page in PHP. For more information, please follow other related articles on the PHP Chinese website!