Home > Backend Development > PHP Tutorial > Detailed explanation of using PHP to get the timestamp of today, tomorrow and yesterday_PHP Tutorial

Detailed explanation of using PHP to get the timestamp of today, tomorrow and yesterday_PHP Tutorial

WBOY
Release: 2016-07-21 15:04:51
Original
793 people have browsed it

Use php to get the time today tomorrow yesterday timestamp
2013-06-20 11:12
echo "Today:".date("Y-m-d")."
";
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 function of
strtotime() function is to parse the date and time description into a Unix timestamp
int strtotime ( string time [, int now] )
?>
This function expects a string containing a US English date format and attempts to parse it into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT), whose value is relative to The time given by the now parameter. If this parameter is not provided, the current system time is used.
-------------------------------------------------- --------------------
Get the code for the day before yesterday and yesterday's date in PHP
It was the same when I went for the interview the day before yesterday, but I couldn't remember it at the time Get up. Just remember date_sub(now(),'interval 1 day');date('Y/m/d h:i:s',mktime(date('h'), date('i')) in MYSQL , date('s'), date('m') , date('d')+1, date('Y')));
------------- -------------------------------------------------- ----------------
First get today's UNIXTIME
Then subtract the seconds of one or two days
Format the subtracted UNIXTIME into a date.
-------------------------------------------------- ----------------------------------
The following is the quoted content:
date_default_timezone_set('Asia/Shanghai');
#Yesterday
echo date("Y/m/d h:i:s",time()-24*60*60);
echo "
";
#The day before yesterday
echo date("Y/m/d h:i:s",time()-2*24*60*60);
?>
------------------------------------------------ -------------------------------
up
------------ -------------------------------------------------- ------------------
There are many methods, let me introduce one:
date("Y/m/d H:i:s ", strtotime("1 days ago"));
date("Y/m/d H:i:s", strtotime("2 days ago"));
------- -------------------------------------------------- -----------------------
date("Y/m/d H:i:s",mktime(0,0,0,date ("m"),date("d")-1,date("Y")));
----------------------- -------------------------------------------------- -------
Calculating time used to be very annoying. Haha, I learned a lesson. Here is the current time next week.
date_default_timezone_set('Asia/Shanghai');
$tmp = time()+60*60*24*7;
print date("m/d/Y H:i:s", $tmp );
------------------------------------------------ ----------------------------------
Add one more:
$time_yes=localtime( time()-24*60*60, true);
$time_b_yes=localtime(time()-2*24*60*60, true);
$yesterday=$time_yes['tm_mday'];
$the_day_before_yes=$time_b_yes['tm_mday'];
--------------------------------- -----------------------------------------------
time()-86400 Yesterday's
The following is the quoted content:
//Yesterday
print date('Y-m-d', strtotime('-1 day'));
//Last week
print date('Y-m-d', strtotime('-1 week'));
//Last month
print date('Y-m-d', strtotime('-1 month' ));
//Last year
print date('Y-m-d' , strtotime('-1 year'));
?>
------------ -------------------------------------------------- ------------------
strtotime gets a timestamp, and then formats it yourself.
strtotime('yesterday');
strtotime('- 2 days');

http://www.bkjia.com/PHPjc/327746.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327746.htmlTechArticleUse php to get the time today tomorrow yesterday timestamp 2013-06-20 11:12 ?php echo "Today:" .date("Y-m-d")."br"; echo "Yesterday:".date("Y-m-d",strtotime("-1 day")), "br"; echo "Tomorrow:".date...
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