PHP Generic Functions, php Generic _ PHP Tutorial

Source: Internet
Author: User
Tags idate
Common PHP functions. PHP common functions, php common 1 ** 2 * timeline functions, Unix timestamp 3 * @ paramint $ time 4*5 functionTranTime ($ time) {6 $ timestrtotime ($ time); 7 $ nowTimet common PHP functions, common php functions
1/** 2 * timeline function, Unix timestamp 3 * @ param int $ time 4 */5 function TranTime ($ time) {6 // $ time = strtotime ($ time); 7 $ nowTime = time (); 8 $ message = ''; 9 // 10 if (idate ('Y', $ nowTime) a year ago )! = Idate ('Y', $ time) {11 $ message = date ('y, m, dday', $ time ); 12} 13 else {14 // 15 $ days = idate ('Z', $ nowTime)-idate ('Z', $ time); 16 switch (true) {17 // 18 cases (0 = $ days) in a day: 19 $ seconds = $ nowTime-$ time; 20 // 21 if ($ seconds <3600) in an hour) {22 // 23 in a minute if ($ seconds <60) {24 if (3> $ seconds) {25 $ message = 'gang '; 26} else {27 $ message = $ seconds. 'seconds ago '; 28} 29} 30 $ message = intval ($ seconds/60 ). 'minute ago '; 31} 32 $ message = idate ('H', $ nowTime)-idate ('H', $ time ). 'hour ago '; 33 break; 34 // Yesterday 35 case (1 = $ days): 36 $ message = 'Yesterday '. date ('H: I ', $ time); 37 break; 38 // The day before yesterday, 39 cases (2 = $ days): 40 $ message = 'day before yesterday '. date ('H: I ', $ time); 41 break; 42 // 43 case (7> $ days) within 7 days: 44 $ message = $ days. 'Day before '; 45 break; 46 // more than 7 days 47 default: 48 $ message = date ('N months j H: I', $ time); 49 break; 50} 51} 52 return $ message; 53}

Timeline 1/** 2 * time axis function, Unix timestamp 3 * @ param int $ time 4 */5 function TranTime ($ time) {6 // $ time = strtotime ($ time); 7 $ nowTime = t...

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.