PHP Salt


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

Version: 2.20.11
Last Build: November 09, 2018 12:24pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
file
graph
html
mail
math
misc
mobile
script
string
system
time
psTime12()
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);
$m = substr("{$m}0",0,2);

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

Changlelog:

11/09/2018 - fixed 24hr decimal to 12hr time to have two digits after decimal


See Also

And a shot out to:

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