PHP Date processing current time plus one year, etc.
Summary : PHP date processing current time plus one year, time interval
<?php
Date_default_timezone_set (' PRC '); Default time zone
echo "Today:", Date ("Y-m-d", Time ()), "<br>";
echo "Today:", Date ("Y-m-d", Strtotime ("June")), "<br>";
echo "Yesterday:", Date ("Y-m-d", Strtotime ("1 day"), "<br>";
echo "Tomorrow:", Date ("Y-m-d", Strtotime ("+1 Day"), "<br>";
echo "One week later:", Date ("Y-m-d", Strtotime ("+1 Week"), "<br>";
echo "2 days a week four hours two seconds after:", Date ("Y-m-d g:h:s", Strtotime ("+1 Week 2 Day 4 hours 2 Seconds"), "<br>";
echo "Next week Four:", Date ("Y-m-d", Strtotime ("next Thursday")), "<br>";
echo "Previous Monday:". Date ("Y-m-d", Strtotime ("Last Monday")). " <br> ";
echo "One months ago:". Date ("Y-m-d", Strtotime ("Last month"). " <br> ";
echo "One months later:". Date ("Y-m-d", Strtotime ("+1 Month")). " <br> ";
echo "Ten years later:". Date ("Y-m-d", Strtotime ("+10 Year")). " <br> ";
?>
One day + N days:
Strtotime can accept the second parameter, type timestamp, for the specified date
echo Date (' y-m-d ', Strtotime ("+1 Day", Strtotime (' 2011-11-01 ')), "\ n";
<?php
echo "Today:", Date (' y-m-d h:i:s '), "<br>";
echo "Tomorrow:", Date (' y-m-d h:i:s ', Strtotime (' +1 Day '));
?>
Last line output current time, next line output tomorrow time
Here +1 Day
Parameter 1 can be modified for any desired number of days can also be changed to year (years), month (months), hour (hours), Minute (min), second (SEC)
Such as
Date (' y-m-d h:i:s ', Strtotime ("+1 day +1 hour +1 minute");
Can be arbitrarily freely combined to achieve the purpose of any output time
Note: This method is intended for trial after 1970, which is the scope of the time stamp.
Another article:
PHP Common date phase function [date plus minus, two date difference, date conversion time Cut] The following code is a number of commonly used date processing functions, can be two times the date of the subtraction, two date difference, date conversion time cut. echo Date (' y-m-d ', Strtotime (' +1 d ', strtotime (' 2009-07-08 ')); Date days Add function echo Date
PHP Common date phase function [date plus minus, two date difference, date conversion time Cut]
The following code is a number of commonly used date processing functions, can be two times the date of the subtraction, the difference between two dates, date conversion time cut.
echo Date (' y-m-d ', Strtotime (' +1 d ', strtotime (' 2009-07-08 '));//Date days Add function
echo Date ("y-m-d", ' 1246982400 ');
Echo ' <br> ';
echo Date ("y-m-d", ' 1279123200 ');
Die ();
$d = "2009-07-08 10:19:00";
echo Date ("Y-m-d", Strtotime ("$d +1 Day"); Date days addition function
function Datetotime ($d)//convert date to time heap intercept
{
$year = ((int) substr ("$d", 0,4));//year acquired
$month = ((int) substr ("$d", 5,2));//Get month
$day = ((int) substr ("$d", 8,2));//Date
Return Mktime (0,0,0, $month, $day, $year);
}
/*
The following function calculates the two dates
*/
$Date _1= "2009-07-08";
echo $Date _1+1;
$Date _2= "2009-06-08";
$Date _list_a1=explode ("-", $Date _1);
$Date _list_a2=explode ("-", $Date _2);
$d 1=mktime (0,0,0, $Date _list_a1[1], $Date _list_a1[2], $Date _list_a1[0]);
$d 2=mktime (0,0,0, $Date _list_a2[1], $Date _list_a2[2], $Date _list_a2[0]);
$Days =round (($d 1-$d 2)/3600/24);
echo "Two dates before the difference between $days days";
This article is from "_xiaohan" blog, please make sure to keep this source http://yingmeng.blog.51cto.com/5365464/1606446
PHP Date Processing