PHP常用函数之格式化时间操作示例(2)
/**
* 计算近一周或近一个月的开始时间戳和结束时间戳
* @param $type 1表示今天,2表示近一周,3表示近一个月
* @return array
*/
function nearFormatTime($type){
$start_time = strtotime(date('Y-m-d 00:00:00'));//今天0点的时间戳
$end_time = $start_time + 86399;//今天23:59的时间戳
$res = array('start_time'=>0,'end_time'=>$end_time);
if($type == 1){
//今天
$res['start_time'] = $start_time;
}else if($type == 2){
//近一周
$res['start_time'] = $start_time - 86400*6;//包括今天,共七天
}else if($type == 3){
//近一个月
$res['start_time'] = $start_time - 86400*30;//包括今天,共31天
}
return $res;
}
PS:这里再为大家推荐几款时间及日期相关工具供大家参考:
在线日期/天数计算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi
在线日期计算器/相差天数计算器:
http://tools.jb51.net/jisuanqi/datecalc
在线日期天数差计算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq
Unix时间戳(timestamp)转换工具:
http://tools.jb51.net/code/unixtime
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php日期与时间用法总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
