0

I have a quickie here, Whenever I try to echo out the time in hours:min:sec using the date() function everything works perfect. But when I try echoing it out using a variable with a value, it always adds up 2 hours.

Take a look at the code:

$time = time();

$past = 120;

//this works perfectly

echo $time = date("H:i:s",$time);

//but this doesnt. it adds 2 hours.

echo $time = date("H:i:s",$time);
0

2 Answers 2

4
string date ( string $format [, int $timestamp ] )

On second using of "date" function, second param is string. Like that 01:01:01. But it must be integer. So converting 01:01:01 to integer; it will be "0". What's your purpose?

Sign up to request clarification or add additional context in comments.

4 Comments

all am trying to do is converting from timestamp to readable format
example: 3600 in timestamp = 01:00:00 in 24 hours system
echo date("H:i:s"); // prints now. 01:39:02. echo date("H:i:s", time()); // prints now. 01:39:02. echo date("H:i:s", mktime("01","39","02", "17", "03", "2011")); // prints now. 01:39:02.
great, i got a better understanding of mktime :)
1

Watch out what You are doing:

//You are assigning a string to $time variable

echo $time = date("H:i:s",$time);

//second call - trying to format date from unix timestamp, which actually is a string with some hours, minutes and seconds

echo $time = date("H:i:s",$time);

EDIT

Maybe You mean this?

$time = time();
$past = 120;
echo date("H:i:s",$time);
echo date("H:i:s",$time - $past);

1 Comment

what am trying to do is format date from unix timestamp, that is what am trying to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.