PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.14.1
Last Build: March 10, 2017 13:28pm (PST)

psTime12d()
Convert 24 Hour to 12 Hour Format


Description:

These function convert 24 hour format to 12 hour format

Two types:
24 Hour to 12 Hour
24 Hour Decimal to 12 Hour




Usage:

$time12 = psTime12("14:45");
$time12 = psTime12d("14.75");





Example:







Code:


function psTime12($t)
{
$t = str_replace(".","|",$t);
$t = str_replace(":","|",$t);

list($h,$m) = explode("|",$t);

$f = "am";
if ($h > 11)
{
$f = "pm";
}
if ($h > 12)
{
$h = $h - 12;
}

return "$h:$m$f";
}


function psTime12d($t)
{
$t = str_replace(".","|",$t);
$t = str_replace(":","|",$t);

list($h,$m) = explode("|",$t);

$f = "am";
if ($h > 11)
{
$f = "pm";
}
if ($h > 12)
{
$h = $h - 12;
}

$m = floor($m * .6);

return "$h:$m$f";
}

Changlelog:


See Also

And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site