Php time functions, that is, out-of-the-box

Source: Internet
Author: User
: This article mainly introduces the php time function, which is ready for use. if you are interested in the PHP Tutorial, please refer to it.
  • Time difference function

Function tranTime ($ time) {$ rtime = date ("m-d H: I", $ time); $ htime = date ("H: I", $ time ); $ time = time ()-$ time; if ($ time <60) {$ str = 'hangzhou';} elseif ($ time <60*60) {$ min = floor ($ time/60); $ str = $ min. 'minute ago ';} elseif ($ time <60*60*24) {$ h = floor ($ time/(60*60); $ str = $ h. 'hour ago '. $ htime;} elseif ($ time <60*60*24*3) {$ d = floor ($ time/(60*60*24 )); if ($ d = 1) $ str = 'Yesterday '. $ rtime; else $ str = 'day before yesterday '. $ rtime;} else {$ str = $ rtime;} return $ str ;}
  • Countdown days hour/minute/second function

Function get_countdown ($ unix_time = '') {if (empty ($ unix_time) return false; if ($ unix_time <time () return array (" day "=> 0, "hour" => 0, "min" => 0, "sec" => 0); $ timediff = $ unix_time-time (); $ days = intval ($ timediff/86400); // calculate the time difference for the whole day $ remain = $ timediff % 86400; // Obtain the remainder of the total number of days, the remaining seconds are recorded as A $ hours = intval ($ remain/3600); // calculate the entire hour by dividing A by 3600 $ remain = $ remain % 3600; // use the remainder of the hour for A division as B $ mins = intval ($ remain/60); // calculate the entire score by dividing 60 with B $ secs = $ remain % 60; // use the integer B to divide the remainder into the remaining seconds $ res = array ("day" => $ days, "hour" => $ hours, "min" => $ mins, "sec" => $ secs); return $ res ;}

The above introduces the php time function, that is, the out-of-the-box function, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.