Skip to content

Instantly share code, notes, and snippets.

@gabrielef
Created February 14, 2020 14:14
Show Gist options
  • Save gabrielef/a01f3c1b351e1378866567bcf238ba6b to your computer and use it in GitHub Desktop.
Save gabrielef/a01f3c1b351e1378866567bcf238ba6b to your computer and use it in GitHub Desktop.
Convert minutes (also negative) like 200 or -300, in the +/-mm:ss notation (+05:00 or -06:00). Useful when working with timezone.
function convertToHoursMins($time) {
$sign = '+';
if ($time < 0)
$sign = '-';
$time = abs($time);
$hours = floor($time / 60);
$minutes = ($time % 60);
return $sign . sprintf('%02d:%02d', $hours, $minutes);
}
echo convertToHoursMins(-100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment