国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP時間類完整實例(非常實用)

2020-03-22 20:20:37
字體:
來源:轉載
供稿:網友
//返回當前時間的月份 time:時間格式為時間戳 2013-3-27 function getmonth($time="",$type=""){ if($time==""){ $time=time(); switch($type){ case 1:$this- month=date("n",$time);//返回格式 3 break; case 2:$this- month=date("m",$time);//返回格式 03 break; case 3:$this- month=date("M",$time);//返回格式 Mar break; case 4:$this- month=date("F",$time);//返回格式 March break; default:$this- month=date("n",$time); return $this- month; //返回當前時間的天數 time:時間格式為時間戳 2013-3-4 function getday($time="",$type=""){ if($time==""){ $time=time(); if($type==1){ $this- day=date("d",$time);//返回格式 04 }else{ $this- day=date("j",$time);//返回格式 4 return $this- //返回當前時間的小時 2010-11-10 1:19:21 20:19:21 function gethour($time="",$type=""){ if($time==""){ $time=time(); switch($type){ case 1:$this- hour=date("H",$time);//格式: 1 20 break; case 2:$this- hour=date("h",$time);//格式 01 08 break; case 3:$this- hour=date("G",$time);//格式 1 20 break; case 4:$this- hour=date("g",$time);//格式 1 8 break; default :$this- hour=date("H",$time); return $this- hour; //返回當前時間的分鐘數 1:9:18 function getminute($time="",$type=""){ if($time==""){ $time=time(); $this- minute=date("i",$time); //格式 09 return $this- minute; //返回當前時間的秒數 20:19:01 function getsecond($time="",$type=""){ if($time==""){ $time=time(); $this- second=date("s",$time); //格式 01 return $this- second; //返回當前時間的星期數 function getweekday($time="",$type=""){ if($time==""){ $time=time(); if($type==1){ $this- weekday=date("D",$time);//格式 Sun }else if($type==2){ $this- weekday=date("l",$time); //格式 Sunday }else{ $this- weekday=date("w",$time);//格式 數字表示 0--6 return $this- weekday; //比較兩個時間的大小 格式 2013-3-4 8:4:3 function compare($time1,$time2){ $time1=strtotime($time1); $time2=strtotime($time2); if($time1 =$time2){ //第一個時間大于等于第二個時間 返回1 否則返回0 return 1; }else{ return -1; //比較兩個時間的差值 function diffdate($time1="",$time2=""){ //echo $time1.'------'.$time2.' br if($time1==""){ $time1=date("Y-m-d H:i:s"); if($time2==""){ $time2=date("Y-m-d H:i:s"); $date1=strtotime($time1); $date2=strtotime($time2); if($date1 $date2){ $diff=$date1-$date2; }else{ $diff=$date2-$date1; if($diff =0){ $day=floor($diff/86400); $hour=floor(($diff%86400)/3600); $minute=floor(($diff%3600)/60); $second=floor(($diff%60)); $this- diffTime='相差'.$day.'天'.$hour.'小時'.$minute.'分鐘'.$second.'秒'; return $this- diffTime; //返回 X年X月X日 function buildDate($time="",$type=""){ if($type==1){ $this- longDate = $this- getyear($time) . '年' . $this- getmonth($time) . '月' . $this- getday($time) . '日'; }else{ $this- longDate = $this- getyear($time) . '年' . $this- getmonth($time) . '月' . $this- getday($time) . '日'.$this- gethour($time).':'.$this- getminute($time).':'.$this- getsecond($time); return $this- longDate;PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 墨玉县| 宜宾市| 元朗区| 江西省| 宜章县| 乌鲁木齐县| 开阳县| 都兰县| 长泰县| 郓城县| 弥渡县| 图们市| 东海县| 遂昌县| 新泰市| 菏泽市| 六盘水市| 昂仁县| 安远县| 海安县| 油尖旺区| 临朐县| 柞水县| 江口县| 甘谷县| 临汾市| 革吉县| 彰化市| 苍南县| 桃园市| 托里县| 突泉县| 景德镇市| 鹤岗市| 德昌县| 许昌市| 富源县| 伽师县| 青冈县| 泰顺县| 静安区|