php calculates hours and rounds them into zeros
Copy code The code is as follows:
/* Author: Yang Yu yangyu@sina .cn */
//The parameter $hours_min is an array, the format of the array is 1:10, and the return value is 1 hour
/*
For example:
$hours_min[0] = '1:10 ';
$hours_min[1] = '2:30';
echo hours_sum($hours_min);
The input is 4, which means a total of 4 hours
*/
function hours_sum($hours_min){
if (!is_array($hours_min)) return false;
$tmp_arr = array();
foreach ($hours_min as $ v){
$tmp_arr = explode(':',$v);
$hour[] = $tmp_arr[0];
$min[] = $tmp_arr[1];
}
$hours = array_sum($hour);
$mins = array_sum($min);
$mins = $mins >= 10 ? str_pad($mins, 2 , 0, STR_PAD_RIGHT) : $mins;
$hours += floor($mins/60);
$hours += $mins%60 >= 30 ? 1 : 0;
return $hours ;
}
Convert date to day of week
Copy code The code is as follows:
/* Author: Yang Yu */
//The input $data parameter is, yy/mm/dd or yy-mm-dd, return the day of the week
function getWeekDay( $date) {
$date = str_replace('/','-',$date);
$dateArr = explode("-", $date);
return date("N", mktime(0,0,0,$dateArr[1],$dateArr[2],$dateArr[0]));
}
PHP converts seconds into hours and minutes ( The format is ** hours ** minutes)
Copy code The code is as follows:
/* Author: Yang Yu */
//Convert seconds (not timestamp) into ** hours ** minutes
function sec2time($sec){
$sec = round($sec /60);
if ($sec >= 60){
$hour = floor($sec/60);
$min = $sec%60;
$res = $hour .' hours';
$min != 0 && $res .= $min.' minutes';
}else{
$res = $sec.' minutes';
}
return $res;
}
http://www.bkjia.com/PHPjc/321111.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321111.htmlTechArticlephp Calculate the hours and round them to zero. Copy the code as follows: /* Author: Yang Yu yangyu@sina. cn */ //The parameter $hours_min is an array, the format of the array is 1:10, and the return value is 1 hour/* For example:...