Created
September 21, 2016 06:03
-
-
Save Panchev/00c7a25502573c3d66df0f54a90651e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timestamp_to_days_and_hours($time) { | |
$d = floor($time/86400); | |
$_d = $d; | |
$h = floor(($time-$d*86400)/3600); | |
$_h = ($h < 10 ? '0' : '').$h; | |
$m = floor(($time-($d*86400+$h*3600))/60); | |
$_m = ($m < 10 ? '0' : '').$m; | |
$s = $time-($d*86400+$h*3600+$m*60); | |
$_s = ($s < 10 ? '0' : '').$s; | |
$time = array(); | |
$time['days'] = $_d; | |
$time['hours'] = $_h; | |
$time['mins'] = $_m; | |
$time['sec'] = $_s; | |
return $time; | |
} | |
function convert_timestamp_to_days_hours_minutes_and_seconds( $timestamp ) { | |
$seconds_in_day = 86400; | |
$seconds_in_hour = 3600; | |
$number_of_days = floor( $timestamp / $seconds_in_day ); | |
$days_timestamp = $number_of_days * $seconds_in_day; | |
$number_of_hours = floor( ( $timestamp - $days_timestamp ) / $seconds_in_hour ); | |
$number_of_hours = ( $number_of_hours < 10 ? '0' : '' ) . $number_of_hours; | |
$hours_timestamp = $number_of_hours * $seconds_in_hour; | |
$number_of_minutes = floor( ( $timestamp - ( $days_timestamp + $hours_timestamp ) ) / 60) ; | |
$number_of_minutes = ( $number_of_minutes < 10 ? '0' : '' ) . $number_of_minutes; | |
$number_of_seconds = $timestamp - ( $days_timestamp + $hours_timestamp + $number_of_minutes * 60); | |
$number_of_seconds = ( $number_of_seconds < 10 ? '0' : '' ) . $number_of_seconds; | |
return array( | |
'days' => $number_of_days, | |
'hours' => $number_of_hours, | |
'minutes' => $number_of_minutes, | |
'seconds' => $number_of_seconds | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment