Skip to content

Instantly share code, notes, and snippets.

@hnq90
Created January 13, 2015 09:46
Show Gist options
  • Select an option

  • Save hnq90/e61e3d774d7b7f155625 to your computer and use it in GitHub Desktop.

Select an option

Save hnq90/e61e3d774d7b7f155625 to your computer and use it in GitHub Desktop.
Seconds to Time Format
public function secondsToTime($value)
{
$hours = 0;
$minutes = 0;
if (filter_var($value)) {
$hours = str_pad(floor($value / (60 * 60)), 2, '0', STR_PAD_LEFT);
$minutes = str_pad(floor(($value - $hours * 60 * 60) / 60), 2, '0', STR_PAD_LEFT);
}
$timeString = Yii::t('app', '{hours} hours {minutes} minutes', ['hours' => $hours, 'minutes' => $minutes]);
return $timeString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment