Use php to get a detailed explanation of the time stamp today tomorrow yesterday

  • 2020-06-15 07:57:18
  • OfStack

Use php to get the time stamp today, tomorrow, yesterday
2013-06-20 11:12
< ?php
Today :".date(" Y-ES10en-ES11en ")." < br > ";
Yesterday :".date(" ES19en-ES20en-ES21en ",strtotime("-1 day"))," < br > ";
echo "tomorrow :".date(" Y-ES32en-ES33en ",strtotime("+1 day"))." < br > ";
After 1 week :".date(" ES43en-ES44en-ES45en ",strtotime("+1 week"))." < br > ";
echo "1 week, 2 days, 4 hours and 2 seconds later :".date(" Y-ES56en-ES57en G: s",strtotime("+1 week 2 days 4 hours 2 seconds")." < br > ";
echo "next Thursday :".date(" ES73en-ES74en-ES75en ",strtotime("next Thursday")." < br > ";
Last week 1:".date(" ES86en-ES87en-ES88en ",strtotime("last Monday")." < br > ";
1 month ago :".date(" ES99en-ES100en-ES101en ",strtotime("last month")." < br > ";
date(" ES112en-ES113en-ES114en ",strtotime("+1 month"))." < br > ";
echo "after 10 years :".date(" Y-ES125en-ES126en ",strtotime("+10 year"))." < br > ";
The strtotime() function resolves the date-time description to an Unix timestamp
int strtotime ( string time [, int now] )
? >
This function expects to take a string containing a US English date format and attempt to parse it into an Unix timestamp (the number of seconds from January 1 1970 00:00:00 GMT) with a value relative to the time given by the now argument, or the current system time if it is not provided.
-------------------------------------------------------------------
Get the dates of the day before and yesterday in PHP
I went to the interview the day before, but I can't remember. date('Y/m/d h: s',mktime(' date '), mktime('i'), date('s'), date(' d')+1, date('Y')));
--------------------------------------------------------------------------------
So let's get today's UNIXTIME
And then subtract the number of seconds in one or two days
Format UNIXTIME as a date.
--------------------------------------------------------------------------------
The following are the quotes:
< ?php
date_default_timezone_set('Asia/Shanghai');
# yesterday.
echo date("Y/m/d h:i:s",time()-24*60*60);
echo " < br > ";
# the day before yesterday
echo date("Y/m/d h:i:s",time()-2*24*60*60);
? >
--------------------------------------------------------------------------------
up
--------------------------------------------------------------------------------
There are many ways, Let me also 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")));
--------------------------------------------------------------------------------
Before the calculation of time is always very annoying, ha ha, learn next, the following is the time next week now.
date_default_timezone_set('Asia/Shanghai');
$tmp = time()+60*60*24*7;
print date("m/d/Y H:i:s", $tmp);
--------------------------------------------------------------------------------
Add 1 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'];
--------------------------------------------------------------------------------
Yesterday's time () - 86400
The following are the quotes:
< ?
/ / 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 you format it yourself.
strtotime('yesterday');
strtotime('-2 day');

Related articles: