php时间和日期函数
问题描述:
我在这里有一个快速, 每当我尝试使用date()
功能回显出hours:min:sec
函数中的时间,一切都很完美。 但是,当我尝试使用具有值的变量回显它时,它总是会累加2个小时。php时间和日期函数
看看代码:
$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);
答
当心你在做什么:
//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);
编辑
也许你的意思呢?
$time = time();
$past = 120;
echo date("H:i:s",$time);
echo date("H:i:s",$time - $past);
我想要做的是从unix时间戳格式化日期,这正是我想要做的。 – saadlulu 2011-03-16 23:35:37
就像一个魅力:) – saadlulu 2011-03-16 23:47:36