Merge PHP computing hours to zero
CopyCode The Code is as follows:/* Author: Yang Yu yangyu@sina.cn */
// The $ hours_min parameter is an array. The array format is and the return value is 1 hour.
/*
For example:
$ Hours_min [0] = '1: 10 ';
$ Hours_min [1] = '2: 30 ';
Echo hours_sum ($ hours_min );
Input 4, that is, 4 hours in total
*/
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 weekCopy codeThe Code is as follows:/* Author: Yang Yu <yangyu@sina.cn> */
// The Input $ data parameter is YY/MM/dd Or YY-mm-dd, and the returned day of the week is
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 (in the format of ** hours)Copy codeThe Code is as follows:/* Author: Yang Yu <yangyu@sina.cn> */
// Converts a second (non-timestamp) to ** hour **.
Function sec2time ($ Sec ){
$ sec = round ($ SEC/60);
if ($ sec >=60) {
$ hour = floor ($ SEC/60 );
$ min = $ sec % 60;
$ res = $ hour. 'hourly ';
$ Min! = 0 & $ res. = $ Min. 'points';
}else {
$ res = $ sec. 'mine';
}< br> return $ res;
}