Summary of php date and time processing functions. Php calculates the hours and converts the hour to zero copy code as follows: * Author: Yang Yu yangyu@sina.cn * parameter $ hours_min is an array, the array format is, returns a 1 hour * Example: php calculates the hours and converts them to zero
The code is as follows:
/* Author: Yang yuyangyu@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 week
The code is as follows:
/* Author: Yang Yu */
// 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)
The code is as follows:
/* Author: Yang Yu */
// 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. 'hour ';
$ Min! = 0 & $ res. = $ min. 'minutes ';
} Else {
$ Res = $ sec. 'mine ';
}
Return $ res;
}
The code for calculating hours in http://www.bkjia.com/PHPjc/321111.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321111.htmlTechArticlephp is as follows:/* Author: Yang Yu yangyu@sina.cn * // The parameter $ hours_min is an array in the format, returns 1 hour/* For example :...