2

I want that system will display current time in (hh:mm:ss) format where 'hh' is for hours, 'mm' is for minutes', 'ss' is for seconds.

I have used time() function.

Here is my code :

<?php
$t=time();
echo($t);
?>

but it is displaying the current time as '1403245168'

Please help me out how can i change this time in another format. Thanks

deepak.mr888
  • 349
  • 2
  • 11
  • 26

5 Answers5

7

Use date function:

<?php
    date("H:i:s"); //Hours:minutes:seconds
?>
Sal00m
  • 2,938
  • 3
  • 22
  • 33
0

The function time() returns always timestamp that is timezone independent (=UTC). For details follow time() in php. To convert timestamp to h:m:s format

echo "UTC:".time(); 
$secs=time();
$h=$secs / 3600 % 24;
$m=$secs / 60 % 60;
$s= $secs % 60;
echo "time=".$h.":".$m.":".$s;
Nidhin
  • 1,818
  • 22
  • 23
-1

Try as follows , You can use both the $_SERVER['REQUEST_TIME'] variable or the time()function. Both of these return a Unix timestamp.

Most of the time these two solutions will yield the exact same Unix Timestamp. The difference between these is that $_SERVER['REQUEST_TIME'] returns the time stamp of the most recent server request and time() returns the current time. This may create minor differences in accuracy depending on your application, but for most cases both of these solutions should suffice.

echo date("h:i:s", time());

http://us.php.net/date

Arshid KV
  • 9,631
  • 3
  • 35
  • 36
-1
php -r 'echo date("H:i:s", time());'

Note that this will yell about time zone, you should use date_default_timezone_set() to set it. Also note that time() is the default argument, so it's unnecessary unless you use a different epoch timestamp.

fin
  • 333
  • 1
  • 4
-1

use Date function with required parameters.

<?php echo date('H:i:s');
?>

here you can see the full parameters description

Vignesh
  • 1,045
  • 2
  • 17
  • 34
  • why the hell an downvote? what is the reason? – Vignesh Jun 20 '14 at 06:40
  • Your answer will return the date and time. OP is looking for time only – Paul Dessert Jun 20 '14 at 06:41
  • I gave an link to the parameter description, he will read it on his own and decide what he want. you should downvote if the answer is completely irrelavant. read the guidlines. just because it returns the date it doesn't mean this is irrelavant. – Vignesh Jun 20 '14 at 06:43