Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
Display Time Using PHP (0 Comments)
Admin: Posted Date: March 3, 2010

How to display time using PHP? This tutorial will show you how to do it. To display time, we use function date(). But you need to format it by choosing the formatting options, for example date("H:i:s").

Display Time Using PHP?

How to display time using PHP? This tutorial will show you how to do it.

To display time, we use function date(). But you need to format it by choose the formatting options. For example, if you want to display a time like "14:25:06", you need to write the PHP code like this:

date("H:i:s");

In this example, "H" represents 24-hour format of an hour with leading zeros 00 through 23; "i" means minutes with leading zeros 00 to 59; and "s" is for seconds, with leading zeros 00 through 59.

So when you have:

echo date("H:i:s");

The output will be something like:

14:25:06

Or if you want to have the output like "2:25:06 pm", change the above code to:

date("h:i:s a");

Here is a list the formatting options for time 14:25:06:

Code Output
date("H:i:s"); 14:25:06
date("H:i:s A"); 14:25:06 PM
date("h:i:s a"); 02:25:06 pm
date("g-i-s a"); 2-25-06 pm

As you can see, you can change the position of the format character to modify the output format. For example:

date("h:i:s a");

and

date("h-i-s a");

use the same characters, but the positions are different. So the output strings are different:

02:25:06 pm

02-25-06 pm

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: