How to echo time in php?

Dear Friends,

I have a question please give me correct answer for this question the question is

how to echo or print time in php?

please tell me the correct answer as soon as possible.

Thank you in advance


It’s pretty easy. What format do you want?

I want time in this format

H:M:S
11:20:15 AM or PM

Thank you.

Something like this?

<?php echo date("h:i:s A"); ?>

There are lots of variations, such as 24-hour/12-hour time etc. http://www.php.net/manual/en/function.date.php

this code is not print current system time

sir i want to echo my computer or server time using php

It works for me. How are you using it?

It prints the time according to the server.
If you want the user’s system time, use JavaScript:

var d = new Date();
console.log(d);

Sir ,

Is it not possible in php.

I am just paste this code (<?php echo date(“h:i:s A”); ?>) in a test file and run it on browser using wamp server.

Then your server isn’t set up correctly.

What output do you see (if any)?

What does the address in the addresbar look like?
For me it is http://localhost/test.php

This address is the address which is look like in addresbar?

This is the output.
11:28:34 AM
time Format is correct but time is not current system time.
For me it is http://localhost/test/test.php

Thank you

Oh ok, well the script is doing what it should (so your server is set up correctly).
The time seems to be in GMT.
What was it that you were hoping to see, or put another way - which timezone are you in?

I want India Time Zone (UTC+05:30)

Thank you


$servertime = mktime();
$itz = $servertime + (5.5 * 3600);
echo date("h:i:s A", $itz);

I think, anyway. Get the local server time, add on 5.5 hours for your time zone difference, then display the result.

This is the code which i want.

$servertime = mktime();
$itz = $servertime + (5.5 * 3600);
echo date("h:i:s A", $itz);

In addition to what droopsnoot says, you can also change your server’s timezone via your php.ini file.

Look for this block:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =

For me the setting would be date.timezone = "Europe/Berlin".

The Indian settings can be found here: http://www.php.net/manual/en/timezones.indian.php