PHP Salt


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

Version: 2.33.2
Last Build: December 29, 2023 20:28pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
db
file
graph
html
mail
math
misc
mobile
script
string
system
time
web
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);
$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:

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