开发者

php time and date function

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 开发者_C百科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);


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?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜