Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*---
- time_dif elapsed time function
- SYNOPSIS elapsed_time = time_diff(time1,time2,lang)
- INPUT
- time1 : start time; time on unix timestamp format
- time2 : end time; time on unix timestamp format
- lang (otional) : language; string 'id' bahasa indonesia, 'en' english ; default 'id'
- OUTPUT
- elapsed_time : elapsed time between time1 and time2, string
- --- */
- function time_diff($time1,$time2,$lang='id')
- {
- $text=Array(
- 'id'=>Array('hari','jam','menit','detik'),
- 'en'=>Array('day[s]','hour[s]','minute[s]','second[s]')
- );
- $ret='';
- $tokens = Array(86400,3600,60,1);
- $difference = $time2 - $time1;
- foreach ($tokens as $id => $value) {
- if ($difference < $value){ echo "1";continue;};
- $numberOfUnits = floor($difference / $value);
- $difference %= $value;
- $ret.=$numberOfUnits.' '.$text[$lang][$id].' ';
- }
- return $ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement