幽灵资源网 Design By www.bzswh.com
开发中,经常用到时间的一些例子,比如昨天,今天,前天,近七天,一周等等。这里整理了一个时间的完整类实例,直接实例化,有需要的可以看看
以下直接代码
<"Content-type:text/html;Charset=utf-8"); class time{ private $year;//年 private $month;//月 private $day;//天 private $hour;//小时 private $minute;//分钟 private $second;//秒 private $microtime;//毫秒 private $weekday;//星期 private $longDate;//完整的时间格式 private $diffTime;//两个时间的差值 //返回年份 time:时间格式为时间 2018-8-21 function getyear($time="",$type=""){ if($time==""){ $time=time(); } if($type==1){ return $this->year=date("y",$time); //返回两位的年份 18 }else{ return $this->year=date("Y",$time); //返回四位的年份 2018 } } //返回当前时间的月份 time:时间格式为时间 2018-8-21 function getmonth($time="",$type=""){ if($time==""){ $time=time(); } switch($type){ case 1:$this->month=date("n",$time);//返回格式 8 break; case 2:$this->month=date("m",$time);//返回格式 08 break; case 3:$this->month=date("M",$time);//返回格式 Aug break; case 4:$this->month=date("F",$time);//返回格式 August break; default:$this->month=date("n",$time); } return $this->month; } //返回当前时间的天数 time:时间格式为时间 2018-8-21 function getday($time="",$type=""){ if($time==""){ $time=time(); } if($type==1){ $this->day=date("d",$time);//返回格式 21 }else{ $this->day=date("j",$time);//返回格式 21 } return $this->day; } //返回当前时间的小时 2018-08-21 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; } //比较两个时间的大小 格式 2018-8-21 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; } } "htmlcode"><"2018-08-21"; $obj = new time(); $year = $obj->getyear($time_var); echo($year); ?>以上其他的方法也可以按照上面那个例子,输出你想要得到的日期,在开发过程中,可以直接放入在扩展库里,直接引用!
标签:
PHP时间类,PHP日期
幽灵资源网 Design By www.bzswh.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
幽灵资源网 Design By www.bzswh.com
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。