Home >Backend Development >PHP Tutorial >Detailed explanation of getting the current date and time in php

Detailed explanation of getting the current date and time in php

WBOY
WBOYOriginal
2016-07-25 09:05:371057browse
  1. date_default_timezone_set("Asia/Hong_Kong");
  2. $time1 = strtotime(date("Y-m-d H:i:s")); //Current system time
  3. $time2 = strtotime( "2013-2-10 17:10:00"); //Holiday time
  4. $time3 = strtotime("2013-1-1"); //New Year's Day 2013
  5. $sub1 = ceil(($time2 - $ time1)/3600); //(60 seconds*60 minutes) seconds/hour
  6. $sub2 = ceil(($time3 - $time1)/86400); //(60 seconds*60 minutes*24 hours) seconds/day
  7. echo "There are still$sub1hours before the holiday!!!";
  8. echo "

    ";

  9. echo "There are stillOh! ";
  10. ?>
Copy code

Explanation: The format of the ceil() function is float ceil(float value), which is a rounding function. The smallest integer less than the parameter value. If there is a decimal part, round it up. It should be noted that the return type of this function is float, not integer.



Statement:
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