12-10-2007, 10:04 AM
|
#2 (permalink)
|
|
The Contributor
Join Date: Dec 2007
Location: Belgium
Posts: 60
Thanks: 6
|
Copied from Kohana's date helper:
PHP Code:
/**
* Adjusts a non-24-hour number into a 24-hour number.
*
* @param integer hour to adjust
* @param string AM or PM
* @return string
*/
public static function adjust($hour, $ampm)
{
$hour = (int) $hour;
$ampm = strtolower($ampm);
switch($ampm)
{
case 'am':
if ($hour == 12)
$hour = 0;
break;
case 'pm':
if ($hour < 12)
$hour += 12;
break;
}
return sprintf('%02s', $hour);
}
As you can see, you can use sprintf to autofill a number with zeroes.
|
|
|
|