Answer 1:
<? PHP Echo Date (' Y '. ' Year '. ' M '. ' Month '. ' d '. ' Day '. ' H:i:s ',strtotime('-1 day '));
Output Result:
Warning:strtotime (): It is not safe for rely on the system ' s timezone settings. You is *required* to use the Date.timezone setting or the Date_default_timezone_set () function. In case you used any of those methods and you is still getting this warning, your most likely misspelled the timezone Iden Tifier. We selected the timezone ' UTC 'for "Now," "Set Date.timezone to select your timezone." In C:\AppServ\www\test2.php on Line 2warning:date (): It isn't safe to rely on the system' s timezone settings. You is *required* to use the Date.timezone setting or the Date_default_timezone_set ()function. Inch CaseYou used any of those methods and is still getting ThisWarning, you are most likely misspelled the timezone identifier. We selected the timezone ' UTC ' forNow, if you set Date.timezone to select your timezone.inchC:\AppServ\www\test2.php on line 22017-03-01 15:06:41
Answer 2:
<? phpdate_default_timezone_set (' UTC '); Echo date (' Y '. ') Year '. ' M '. ' Month '. ' d '. ' Day '. ' H:i:s ', Strtotime ('-1 day '));
Operation Result:
March 01, 2017 15:06:43
Date ()- format a local time/date
string Date string $format $timestamp ] )
Returns a string timestamp
that is the result of an integer in a given format string. If no timestamp is given, the local current time is used. In other words, timestamp
it is optional and the default value is Time ().
Note: to convert the time that a string is expressed to a timestamp, you should use strtotime (). In addition some databases have some functions to convert their time format into timestamps (such as MySQL's?). Unix_timestamp function).
Strtotime ()- resolves a datetime description of any string to a Unix timestamp
Definition and Usage
The strtotime () function resolves the date or time description of any English text to a Unix timestamp (the number of seconds from January 1 1970 00:00:00 GMT).
Strtotime string $time $now Time () ] )
Parameters
-
time:
Date/Time string. The correct format is described in the date and time format .
-
now:
The timestamp used to calculate the return value. If this argument is omitted, the current time is used.
return value
Success returns a timestamp, otherwise it is returned FALSE
. This function returns 1on Failure before PHP 5.1.0.
Example
Resolves the English text date time to a Unix timestamp:
<?PHPEcho(Strtotime("Now"). "<br>");Echo(Strtotime("October 1980"). "<br>");Echo(Strtotime("+5 hours"). "<br>");Echo(Strtotime("+1 Week"). "<br>");Echo(Strtotime("+1 Week 3 days 7 hours 5 Seconds"). "<br>");Echo(Strtotime("Next Monday"). "<br>");Echo(Strtotime("Last Sunday"));?>
Operation Result:
Http://www.w3school.com.cn/php/func_date_strtotime.asp
http://php.net/manual/zh/function.strtotime.php
mktime- get a date for Unix timestamp
Date converted to timestamp
PHP provides functions that can easily convert various forms of a date to a timestamp, which is mainly:
- Strtotime (): Resolves the datetime description of any English text to a timestamp.
- Mktime (): Gets the timestamp from the date.
Print the previous day in PHP, the print format is May 10, 2007 22:21:21