Php timeline function, just one minute ago, one hour ago, one day ago

Source: Internet
Author: User
Tags php timeline
Php timeline function, which is a common time processing function in php just one minute ago, one hour ago, or one day ago: time (): returns the current Unix timestamp ?. Date (): format a local time/date. Getdate (): Get date/time information. Mktime (): normal date to timestamp. Mktime (php timeline function, just one minute ago, one hour ago, one day ago

Common php time processing functions:

Time (): returns the current Unix timestamp ?.

Date (): format a local time/date.

Getdate (): Get date/time information.

Mktime (): normal date to timestamp. Mktime (0, 0, 0, 9, 18,201 1)

The following is a timeline processing function.

/*** Time formatting */static function formatDate ($ 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 ;}
?

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.