PHP Salt


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

Version: 2.20.2
Last Build: October 16, 2017 12:40pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
file
graph
html
mail
math
misc
mobile
script
string
system
time
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;
}

if ($h == 0) { $h = 12; }

$m = substr("00{$m}",-2);

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