Sometimes, we need to get the last modification time of the current page in PHP for different uses. Since we are using PHP, we can easily get the last modification time of the current page by using getlastmod() PHP function.
Using getlastmod() Function: The getlastmod() function is used to get the last modification time of the current page. This function is easy and powerful.
Syntax:
$last_modification=”Last modified on: ” . date (“F d Y H:i:s.”, getlastmod());
Example :The following is the complete code to get and show the last modification time of the current page.
PHP
<?php
$last_modification = "Last modified: " . date ( "F d Y H:i:s." , getlastmod ());
echo $last_modification ;
?>
|
Output
Last modified: February 25 2021 12:40:34.
Note: We can directly use it as the following.
echo "Last modified: " . date ("F d Y H:i:s.", getlastmod());
Using filemtime() Function: The filemtime() function in PHP is an inbuilt function that is used to return the last time of a specified file when its content was modified.
Example:
PHP
<?php
echo filemtime ( "index.html.txt" );
echo "Last modified: " . date ( "F d Y H:i:s." ,
filemtime ( "index.html" ));
?>
|
Output:
Last modified: February 13 2021 13:01:35.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
08 Mar, 2021
Like Article
Save Article