PHP finds the time after a time interval of n days, weeks, months, and years

WBOY
Release: 2016-07-25 08:46:10
Original
1196 people have browsed it
  1. date_default_timezone_set('PRC'); //Set the time zone
  2. $date1 = strtotime('2015-01-01'); //Convert date to timestamp
  3. $date2 = time( ); //Get the timestamp of the current time
  4. $nowtime=strftime("%Y-%m-%d",$date2); //Format the output date
  5. $days=round(($date1-$ date2)/3600/24); //Rounding
  6. echo "Today is".$nowtime."";
  7. echo "
    distance ".strftime("%Y-%m-%d ",$date1)."Also".$days."Days


    ";
  8. echo "Current time" . date("Y-m-d h:i:s",strtotime("now")). "
    ";
  9. echo "Time the day after tomorrow" . date("Y-m-d h:i:s",strtotime("+2 day")). "
    ";
  10. echo "Time next week" . date("Y-m-d h :i:s",strtotime("+1 week")). "
    ";
  11. echo "Next month's time" . date("Y-m-d h:i:s",strtotime("+1 month ")). "
    ";
  12. echo "Next year's time" . date("Y-m-d h:i:s",strtotime("+1 year")). "
    ";
  13. 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")). "
    ";
  14. echo "Next Thursday time" . date("Y-m-d h:i:s",strtotime("next thursday")). "
    ";
  15. echo "Last Monday time" . date ("Y-m-d h:i:s",strtotime("last monday")). "
    ";
  16. echo "2015-01-04 3 days later" . date("Y-m-d h:i: s",strtotime("+3 day",strtotime('2015-01-04')));
  17. ?>
Copy code

PHP


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!