码迷,mamicode.com
首页 > Web开发 > 详细

php求出当年/月/日的时间缀

时间:2018-04-03 18:15:33      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:php求出当年/月/日的时间缀

/* 时间转时间缀 @param $time 传入时间 @param $stime 开始时间缀 @param $etime 结束时间缀 */ function timeSwitch($time){ if(preg_match(‘/^\d{4}$/‘,$time)){ // 年 $stime = strtotime("{$time}-01-01 00:00:00"); $etime = strtotime("{$time}-01-01 00:00:00 +1year"); }elseif(preg_match(‘/^\d{4}-{1}\d{1,2}$/‘,$time)){ // 月 $stime = strtotime("{$time}-01 00:00:00"); $etime = strtotime("{$time}-01 00:00:00 +1month"); }elseif(preg_match(‘/^\d{4}-{1}\d{1,2}-{1}\d{1,2}$/‘,$time)){ // 日 $stime = strtotime("{$time} 00:00:00"); $etime = strtotime("{$time} 00:00:00 +1day"); }else{ // 格式错误 return false; } $arr = array( ‘stime‘=>$stime, ‘etime‘=>$etime ); return $arr; }

php求出当年/月/日的时间缀

标签:php求出当年/月/日的时间缀

原文地址:http://blog.51cto.com/12173069/2094367

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!