Conversion from 12 Hour to 24 Hour

Conversion from 12 Hour to 24 Hour

Many people using either 12 hour time format or 24 hour time format. It also easy for us to convert it into time format that we familiar with. We also can use both. However, database time format can only accept 24 hour time format. Therefore Conversion from 12 Hour to 24 Hour is a must.

For people that does not familiar with Conversion from 12 Hour to 24 Hour, I’ll give an example.

12 hour time format 24 hour time format
00:00 am 00:00
01:00 am 01:00
11:00 am 11:00
12:00 pm 12:00
01:00 pm 13:00
11:00 pm 23:00
00:00 am 00:00

The php code that will handle this Conversion from 12 Hour to 24 Hour is below.

$ampm = "" //fill it either with am or pm
$hour = "" //fill it with hour
$min = "" //fill it with minute

if($ampm == 'PM' && $hour != 12)
{$hour = $hour + 12;}
echo "$hour:$min";

Congratulation we just made a simple Conversion from 12 Hour to 24 Hour programs.

Good luck.

http://septiadi.com/2011/03/01/conversion-from-12-hour-to-24-hour/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: