Infolinks

Breaking

Adsense

Wednesday, January 20, 2016

PHP DATE AND TIME FORMAT: Display Time in 12 Hour Format from 24 Hour Format

Date functions lets you get and format the date and time for use in queries, calendar functions and printing of date and time.

The date() function returns the current server timestamp and you can format it according to a set of parameters. The syntax is date(format,timestamp); If timestamp is not given, current date and time is assumed.

Here are some date() function formats for your reference.


Usually, the format that we used to save time in our table is H:i:s in which the result is something like this: 14:00:00 which is in 24 hour format. So to make your time more readable to users, you need to format it in 12 hour format.

Code
<?php
$time="19:04:28";
echo date('h:i:s A', strtotime($time);
?>

Output


PHP DATE AND TIME FORMAT: Display Time in 12 Hour Format from 24 Hour Format

No comments:

Post a Comment

Adbox