This article to share to everyone is about the PHP time function encapsulation Implementation code, the content is very valuable, I hope to help the need for small partners.
One, two days of difference between dates
function DateDiff ($time 1, $time 2, $absolute = False) { $time 1 = ($temp = strtotime ($time 1))? $temp: $time 1); $time 2 = ($temp = Strtotime ($time 2))? $temp: $time 2); $temp = (Strtotime (date (' Ymd ', $time 1))-Strtotime (Date (' Ymd ', $time 2))/86400; Return $absolute? ABS ($temp): $temp;}
PHP comes with a function date_diff need to pass in the DateTime object, more troublesome. The top method returns the number of days between two time/timestamp differences. The idea is: if it is time, turn the time into a timestamp, format it to 0 points of the day and then convert back to timestamp, subtract divided by 86400. Of course, if the method is just a two-timestamp difference in number of days, the first line of the second line of the conversion timestamp code can be removed. 2018-01-01 23:59:59 and 2018-01-02 00:00:00 difference 1 days. 2018-01-01 00:00:00 and 2018-01-02 23:59:59 also differ by 1 days.
Second, current time milliseconds
function msec () { return sprintf ('%.0f ', Microtime (True) * 1000);}
PHP does not have a function to directly return milliseconds, here is a microsecond format for the production of microseconds.