PHP finds the time after a time interval of n days, weeks, months, and years
Release: 2016-07-25 08:46:10
Original
1196 people have browsed it
- date_default_timezone_set('PRC'); //Set the time zone
- $date1 = strtotime('2015-01-01'); //Convert date to timestamp
- $date2 = time( ); //Get the timestamp of the current time
- $nowtime=strftime("%Y-%m-%d",$date2); //Format the output date
- $days=round(($date1-$ date2)/3600/24); //Rounding
- echo "Today is".$nowtime."";
- echo "
distance ".strftime("%Y-%m-%d ",$date1)."Also".$days."Days
";
-
- echo "Current time" . date("Y-m-d h:i:s",strtotime("now")). "
";
- echo "Time the day after tomorrow" . date("Y-m-d h:i:s",strtotime("+2 day")). "
";
- echo "Time next week" . date("Y-m-d h :i:s",strtotime("+1 week")). "
";
- echo "Next month's time" . date("Y-m-d h:i:s",strtotime("+1 month ")). "
";
- echo "Next year's time" . date("Y-m-d h:i:s",strtotime("+1 year")). "
";
- echo "The time in 2 days, 4 hours and 2 seconds next week" . date("Y-m-d h:i:s",strtotime("+1 week 2 days 4 hours 2 seconds")). "
";
- echo "Next Thursday time" . date("Y-m-d h:i:s",strtotime("next thursday")). "
";
- echo "Last Monday time" . date ("Y-m-d h:i:s",strtotime("last monday")). "
";
- echo "2015-01-04 3 days later" . date("Y-m-d h:i: s",strtotime("+3 day",strtotime('2015-01-04')));
-
- ?>
Copy code
|
PHP
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
Latest Articles by Author
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31
-
2024-10-11 11:48:01
-
2024-10-11 11:35:40
-
2024-10-11 11:33:11
-
2024-10-11 11:18:01