PHP Output Time difference function
Copy CodeThe code is as follows:
Date_default_timezone_set (' PRC '); Default time zone
echo "Today:", Date ("Y-m-d", Time ()), "
";
echo "Today:", Date ("Y-m-d", Strtotime ("June 2008")), "
";
echo "Yesterday:", Date ("Y-m-d", Strtotime ("-1 Day")), "
";
echo "Tomorrow:", Date ("Y-m-d", Strtotime ("+1 Day"), "
";
echo "One week later:", Date ("Y-m-d", Strtotime ("+1 Week")), "
";
echo "2 days a week four hours two seconds later:", Date ("Y-m-d g:h:s", Strtotime ("+1 Week 2 Day 4 hours 2 Seconds")), "
";
echo "Next week Four:", Date ("Y-m-d", Strtotime ("next Thursday")), "
";
echo "Previous Monday:". Date ("Y-m-d", Strtotime ("Last Monday")). "
";
echo "One months ago:". Date ("Y-m-d", Strtotime ("Last month"). "
";
echo "One months later:". Date ("Y-m-d", Strtotime ("+1 Month")). "
";
echo "Ten years later:". Date ("Y-m-d", Strtotime ("+10 Year")). "
";
?>
When learning PHP, it is often used to get the date before or after a certain time period. Now it's collected and you can expand it
Copy CodeThe code is as follows:
Get the day of the Week (1-7)
function Getweek ($times)
{
$res = Date (' W ', Strtotime ($times));
if ($res ==0)
$res = 7;
return $res;
}
Get the time of day
function GetTime ($times)
{
$res = Date (' H:i ', Strtotime ($times));
return $res;
}
Get the time in a few months now
function GetMonth ($Month, $type = ' l ')
{
if (!strcmp ($type, ' B '))
$res =date ("y-m-d h:i:s", Strtotime ("-$Month months"));
if (!strcmp ($type, ' l '))
$res =date ("y-m-d h:i:s", Strtotime ("+ $Month months"));
return $res;
}
Get current time
function GetCurrentDateTime ()
{
$res =date ("y-m-d h:i:s", Time ());
return $res;
}
Gets the time before or after the current time interval
function Getdiffhours ($hours, $type = ' l ')
{
if (!strcmp ($type, ' B '))
$res =date ("y-m-d h:i:s", Strtotime ("-$hours Hour"));
if (!strcmp ($type, ' l '))
$res =date ("y-m-d h:i:s", Strtotime ("+ $hours Hour"));
return $res;
}
Interval a few minutes before or after the time
function Getdiffminute ($Minute, $type = ' l ')
{
if (!strcmp ($type, ' B '))
$res =date ("y-m-d h:i:s", Strtotime ("-$Minute Minute"));
if (!strcmp ($type, ' l '))
$res =date ("y-m-d h:i:s", Strtotime ("+ $Minute Minute"));
return $res;
}
Interval a few seconds before or after the time
function Getdiffsec ($sec, $type = ' l ')
{
if (!strcmp ($type, ' B '))
$res =date ("y-m-d h:i:s", Strtotime ("-$sec Second"));
if (!strcmp ($type, ' l '))
$res =date ("y-m-d h:i:s", Strtotime ("+ $sec Second"));
return $res;
}
Interval a few weeks before or after the time
function Getdiffweek ($Week, $type = ' l ')
{
if (!strcmp ($type, ' B '))
$res =date ("y-m-d h:i:s", Strtotime ("-$Week Week"));
if (!strcmp ($type, ' l '))
$res =date ("y-m-d h:i:s", Strtotime ("+ $Week Week"));
return $res;
}
Time interval between days
function Getdiffdays ($days, $type = ' l ')
{
if (!strcmp ($type, ' B '))
$res =date ("y-m-d h:i:s", Strtotime ("-$days Day"));
if (!strcmp ($type, ' l '))
$res =date ("y-m-d h:i:s", Strtotime ("+ $days Day"));
return $res;
}
Time before or after a few years
function Getdiffyears ($year, $type = ' l ')
{
if (!strcmp ($type, ' B '))
$res =date ("y-m-d h:i:s", Strtotime ("-$year Year"));
if (!strcmp ($type, ' l '))
$res =date ("y-m-d h:i:s", Strtotime ("+ $year Year"));
return $res;
}
http://www.bkjia.com/PHPjc/326523.html www.bkjia.com true http://www.bkjia.com/PHPjc/326523.html techarticle PHP Output time difference function copy code code as follows: Php date_default_timezone_set (' PRC ');//Default TimeZone echo "Today:", Date ("Y-m-d", Time ()), "BR"; echo "Today: ", Date (" y-m-d ", Strt ...