PHP Judge file modification time and date function code

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags code date file filemtime function name php php tutorial

PHP Tutorial determines file modification time with date function
This script when the page was last revised and output as 20 minutes ago, or XX days before the date ... Or even if you don't update too much-20 weeks before the show!

//file Name
$last _modified = Filemtime ("file.php");
 
{
$timediff = time ()-$last _modified;
 
if ($timediff < 3600)
{
if ($timediff <)
{
$returndate = "1 minute ago.";
}
Else
{
$returndate = intval ($timediff/60). "Minutes ago."
}
}
Else if ($timediff < 7200)
{
$returndate = "1 hour ago.";
}
Else if ($timediff < 86400)
{
$returndate = intval ($timediff/3600). "Hours ago."
}
Else if ($timediff < 172800)
{
$returndate = "1 day ago."
}
Else if ($timediff < 604800)
{
$returndate = intval ($timediff/86400). "Days ago."
}
 
Else if ($timediff < 1209600)
{
$returndate = "1 week ago.";
}
Else if ($timediff < 3024000)
{
$returndate = intval ($timediff/604900). "Weeks ago."
}
Else
{
$returndate = @date (' n-j-y ', $timestaMP);
if ($type = = "Fulldate")
{
$returndate = @date (' n-j-y, h:i ', $timestamp);
 
}
 
Else if ($type = = "Time")
{
 
$returndate = @date (' h:i ', $timestamp);
 
}
 
}
//display It
Print ("Last flushes:");
Print ($returndate);
 
}
?

It should be easy to understand.

$ last_modified = filemtime ("file.php"); -Change file.php to file you want to connect.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.