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...