Created
February 14, 2020 14:14
-
-
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.
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 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