PHP calculates the number of hours and breaks it down
Copy Code code as follows:
/* Author: Yangyu yangyu@sina.cn * *
Parameter $hours_min array with a format of 1:10, returned to 1 hours
/*
For example:
$hours _min[0] = ' 1:10 ';
$hours _min[1] = ' 2:30 ';
Echo hours_sum ($hours _min);
The input is 4, which means total 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 a date to a week
Copy Code code as follows:
/* Author: Yangyu <yangyu@sina.cn> *
The input $data parameter is, YY/MM/DD or YY-MM-DD, returns 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 to hours and minutes (format * * * hours * *)
Copy Code code as follows:
/* Author: Yangyu <yangyu@sina.cn>/*
//convert seconds (non time stamps) to * * * hours * * Nction Sec2time ($sec) {
$sec = round ($sec/60);
if ($sec >=) {
$hour = floor ($sec/60);
$min = $sec% 60;
$res = $hour. ' Hour ';
$min!= 0 && $res. = $min. ' Minute ';
}else{
$res = $sec. ' Minutes ';
}
Return $res;
}