-
- function getWeekName($data,$format = '星期')
- {
- $week = date( "D " , $數據);
- switch($week)
- {
- case "Mon ":
- $current = $format."一";
- 休息;
- case "Tue ":
- $current = $format."二";
- 休息;
- case "Wed ":
- $current = $format."三";
- 休息;
- case "Thu ":
- $current = $format."四";
- 休息;
- case "Fri ":
- $current = $format."五";
- 休息;
- case "Sat ":
- $current = $format."六"; 休息;
- 案例"Sun ":
- $current = $format."Day";
- 休息;
- }
- 回傳$current;
- }
-
- echo '今天是:'.getWeekName(time(),'星期');
- echo '
';
- echo '今天是:'.getWeekName(time(),'禮拜');
- echo '
';
- echo '2010-12-12是:'.getWeekName(strtotime('2010-12-12' ),'禮拜');
- ? >
複製程式碼
4、取得類似文章發表的幾小時前等效果的自訂函數
-
- function time2Units ($time)
- {
- $year = Floor($time / 60 / 60 / 24 / 365);
- $時間-= $年* 60 * 60 * 24 * 365;
- $月= 下限($時間/ 60 / 60 / 24 / 30);
- $時間-= $月* 60 * 60 * 24 * 30;
- $week = 下限($time / 60 / 60 / 24 / 7);
- $time -= $week * 60 * 60 * 24 * 7; > $day = 樓層($time / 60 / 60 / 24);
- $時間-= $天* 60 * 60 * 24;
- $小時= 樓層($時間/ 60 / 60);
- $小時= 樓層($時間/ 60 / 60);
- $小時= 樓層($時間/ 60 / 60);
- $小時= 樓層($時間/ 60 / 60);
- $時間-= $小時* 60 * 60;
- $分鐘= 下限($時間/ 60);
- $時間-= $分鐘* 60;
- $秒= $時間;
- $elapse = '';
-
- $unitArr = array('年'=>'年', '月'=>'月', '週'=>'週', '天'=>'日',
- '小時'=>'小時', '分鐘'=>'分鐘', '秒'=>'秒'
- );
-
- foreach ( $unitArr as $cn => $u )
- {
- if ( $$u > 0 )
- {
- $elapse = $$u 。 $cn;
- 休息;
- }
- }
-
- 返回$elapse;
- }
-
- $過去= 2052345678; // 發布日期 $diff = $now - $past;//出口值
-
- echo '發表於' . time2Units($diff) 。 '前';
? >
複製程式碼
另一種,個人認為比較好的:
-
-
-
function time_tran($the_time){
- $now_time = date("Y-m-d H:i:s",time (i:i:s",time (i:i:s) )+8*60*60);
- $now_time = strtotime($now_time);
- $show_time = strtotime($the_time);
- $dur = $now_time - $show_time;
- if(> if(> if( $dur return $the_time;
- }else{
- if($dur return $dur.'秒前';
- }else{
- if($dur 返回樓層($dur/60).'分鐘前';
- }else{
- if($dur 返回樓層($ dur/3600).'小時前';
- }else{
- if($dur return Floor($dur/86400).'天前';
- }else{
- return $the_time;
- }
- }
- }
- }
- }
- }
?>
複製程式碼
5.依兩時差具體算相差時間
-
-
function getTime( $val ){
- if($val>0){
- $nTime['nDay '] = (int)($val/(3600*24));
- $nTime['nHour'] = (int)($val%(3600*24)/3600);
- $nTime[ 'nMin'] = (int)($val%(3600*24)%3600/60);
- $nTime['nSec'] = (int)($val%(3600*24)%3600%60 );
- }
- return $nTime ;
- }
- function getStrTime( $val ){
- $aTime = getTime($val);
- $dtoc = array('nDay' =>'天','nHour'=>'小時','nMin'=>'分','nSec'=>'秒');
- if( $aTime ){
- foreach( $aTime as $k=>$v){
- if($v){
- $cTime .= $v.$dtoc[$k];
- }
- }
- }else{
- $cTime = '已結止';
- }
- return $cTime;
- }
- ?>
複製代碼
|