Heim  >  Artikel  >  Backend-Entwicklung  >  php中倒计时的问题

php中倒计时的问题

WBOY
WBOYOriginal
2016-06-23 13:54:01940Durchsuche

源代码是这样的

$time1=strtotime(date("Y-m-d H:i:s"));
$time2=strtotime("2014-11-11 00:00:00");
$time3=strtotime("2013-01-01");
$sub1=ceil(($time2-$time1)/3600);
$sub2=ceil(($time3-$time1)/86400);
echo $time2."
";
echo $time1."
";
echo "距离时间$sub1";
 
?>

最后输出的结果是
Strict Standards: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in D:\AppServ\www\base1\strcmp.php on line 18
1415664000
1405231125
距离时间2899


那位大神帮忙解决一下哦


回复讨论(解决方案)

你没有设置时区,或时区代码是错误的
php.ini 中
date.timezone = PRC;北京时间
或程序中
date_default_timezone_set('PRC');

非常感谢感谢你

还有一个问题 本来明明是除以了3600,按理来说应该显示19小时 可显示的是2899  这么多

为啥呢
$time1=strtotime(date("Y-m-d H:i:s")); //这不是今天吗? 2014-07-13
$time2=strtotime("2014-11-11 00:00:00");

距离 2014-11-11 不是有 120 天吗?

我说那个显示的是2899,,怎么能够转化为120天呢

自己根据你算出的时间差进行具体的转换,就可以实现倒计时的具体时间。
可以大概的参考下这个:

http://blog.csdn.net/u011619326/article/details/37740129

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn