PHP Tutorial

PHP Examples

PHP Practice

PHP Code to print current time in various formats

In this PHP code, we will learn how to get current time and print the time in various different formats?

Source Code and Output to get and print Current Time

<?php
/*print time in HH:MM:SS*/
print "Current time in HH:MM:SS format: " . date("h:i:s");
print "</br>";

/*print time in HH:MM:SS*/
print "Current time in HH:MM:SS am/pm format: " . date("h:i:s a");
print "</br>";

/*print time in HH:MM:SS*/
print "Current time in HH:MM:SS AM/PM format: " . date("h:i:s A");
print "</br>";

/*print time in HH:MM:SS*/
print "Current time in HH24:MM:SS format: " . date("H:i:s A");
print "</br>";
?>

Output

Current time in HH:MM:SS format: 02:29:27
Current time in HH:MM:SS am/pm format: 02:29:27 pm
Current time in HH:MM:SS AM/PM format: 02:29:27 PM
Current time in HH24:MM:SS format: 14:29:27 PM

The following PHP topics are used in the above examples:

PHP Basic Programs »



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.