Home > Backend Development > PHP Tutorial > php output time difference

php output time difference

WBOY
Release: 2016-08-08 09:30:53
Original
1054 people have browsed it

For personal testing, use strtotime("-1 day") directly;

displays the day before today, which is yesterday. Today is determined based on the current Unix time cutoff.

date_default_timezone_set('PRC'); //Default time zone
echo "Today:",date("Y-m-d",time()),"
";
echo "Today:", date("Y-m-d",strtotime("18 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 "One week, two days, four hours and two seconds later:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "
";
echo "Next Thursday:",date("Y-m-d",strtotime("next Thursday")), "
";
echo "Last Monday:".date("Y-m-d",strtotime("last Monday"))."
";
echo "One month ago:".date("Y-m-d",strtotime("last month"))."
";
echo "One month later:" ".date("Y-m-d",strtotime("+1 month"))."
";
echo "Ten years later:".date("Y-m-d",strtotime("+10 year")). "
";
?>

//The time before or after the interval in minutes
function GetMinute($Minu,$type='l')
{
if(!strcmp($type,' b'))
$res=date("Y-m-d H:i:s",strtotime("-$Minu minute"));

else $res=0;
if(!strcmp($type,'l' ))
$res=date("Y-m-d H:i:s",strtotime("+$Minu minute"));

else $res=0;
return $res;
}
//How many seconds ago Or the time after
function GetSec($sec,$type='l')
{
if(!strcmp($type,'b'))
$res=date("Y-m-d H:i:s",strtotime ("-$sec second"));

else $res=0;
if(!strcmp($type,'l'))
$res=date("Y-m-d H:i:s",strtotime(" +$sec second"));

else $res=0;
return $res;
}

The above introduces the PHP output time difference, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template