Skip to content

Instantly share code, notes, and snippets.

@sungitly
Created March 9, 2015 14:19
Show Gist options
  • Save sungitly/608152339334e70d2747 to your computer and use it in GitHub Desktop.
Save sungitly/608152339334e70d2747 to your computer and use it in GitHub Desktop.
Convert seconds to human readable time duration
static $periods = array(
'天' => 86400,
'小时' => 3600,
'分钟' => 60,
'秒' => 1
);
public function friendlyTime($timestamp)
{
$timeStr = '';
foreach (Device::$periods as $period => $value) {
if ($timestamp >= $value) {
$timeStr = $timeStr . floor($timestamp / $value) . $period;
$timestamp = $timestamp % $value;
}
}
return $timeStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment