- A+
所属分类:实用软件
日期
当日
date('Y-m-d")
date('Y-m-d 00:00:00')
取日期:年 月 日
date("Y", strtotime($startday))
date("m", strtotime($startday))
date("d", strtotime($startday))
上月 下月
$last_mont_first_date = date('Y-m-01 00:00:00',strtotime('last month'))
$next_mont_first_date = date('Y-m-20 00:00:00',strtotime('next month'))
2个日期比较大小的方法
protected function DateCompare($dateString1,$dateString2){
$month1 = date("m", strtotime($dateString1));
$month2 = date("m", strtotime($dateString2));
$day1 = date("d", strtotime($dateString1));
$day2 = date("d", strtotime($dateString2));
$year1 = date("Y", strtotime($dateString1));
$year2 = date("Y", strtotime($dateString2));
$hour1 = date("H", strtotime($dateString1));
$hour2 = date("H", strtotime($dateString2));
$minute1 = date("i", strtotime($dateString1));
$minute2 = date("i", strtotime($dateString2));
$second1 = date("s", strtotime($dateString1));
$second2 = date("s", strtotime($dateString2));
$do1 = mktime($hour1, $minute1, $second1, $month1, $day1, $year1);
$do2 = mktime($hour2, $minute2, $second2, $month2, $day2, $year2);
if($do1<$do2){
return '0';
}
if($do1==$do2){
return '1';
}
if($do1>$do2){
return '2';
}
}
2个时间的相减,返回秒、分钟、小时,小数点2位四舍五入
protected function getLengthOfTime($start,$end,$type,$decimalpoint){
$lengthoftime = strtotime($end) - strtotime($start);
if($lengthoftime == false)return 0;
switch($type){
case 'minute':
$lengthoftime = $lengthoftime / 60.0;
break;
case 'hour':
$lengthoftime = $lengthoftime / 60.0 / 60.0;
break;
default:
;
}
return round($lengthoftime,$decimalpoint);
}
是否在时间范围内,如果是return true
protected function ChkDateTimeRange($start1,$end1,$start2,$end2){
$startday1 = strtotime($start1);
$endday1 = strtotime($end1);
$startday2 = strtotime($start2);
$endday2 = strtotime($end2);
if(($startday1 >= $startday2 && $startday2 <= $endday1) && ($startday1 >= $endday2 && $endday2 <= $endday1)){
return true;
}
return false;
}
数组
长度:0不包含二维数组,1包含二维数组sizeof(array(),0)