This article introduces a time-date conversion custom function in php, which can convert events in seconds to time formats such as year, month, day, and hour. FunctionSec2Time ($ time) {if (
This article introduces a time-date conversion custom function in php, which can convert events in seconds to time formats such as year, month, day, and hour.
- Function Sec2Time ($ time ){
- If (is_numeric ($ time )){
- $ Value = array (
- "Years" => 0, "days" => 0, "hours" => 0,
- "Minutes" => 0, "seconds" => 0,
- );
- If ($ time> = 31556926 ){
- $ Value ["years"] = floor ($ time/31556926 );
- $ Time = ($ time % 31556926 );
- }
- If ($ time> = 86400 ){
- $ Value ["days"] = floor ($ time/86400 );
- $ Time = ($ time % 86400 );
- }
- If ($ time> = 3600 ){
- $ Value ["hours"] = floor ($ time/3600 );
- $ Time = ($ time % 3600 );
- }
- If ($ time> = 60 ){
- $ Value ["minutes"] = floor ($ time/60 );
- $ Time = ($ time % 60 );
- }
- $ Value ["seconds"] = floor ($ time );
- Return (array) $ value;
- } Else {
- Return (bool) FALSE;
- }
- }