周日倒计时

时间:2012-02-25 19:35:04

标签: php javascript jquery

我目前正在为我的网站创建一个脚本,该脚本将计入每周的星期日,每周一次。

示例:

用户在星期六上午11:30访问该网站,他们将受到以下欢迎:

“下次更新此页面的时间为0天,12小时30分钟。”

有什么想法吗?

3 个答案:

答案 0 :(得分:4)

您可以使用这个小技巧获取下周日午夜的时间戳:

$sunday = strtotime('next Sunday');

请参阅this answer了解如何将其格式化为有用的内容。现在我明白了:

print_r(dateDifference($sunday, time()));
Array
(
    [years] => 0
    [months_total] => 0
    [months] => 0
    [days_total] => 0
    [days] => 0
    [hours_total] => 4
    [hours] => 4
    [minutes_total] => 256
    [minutes] => 16
    [seconds_total] => 15387
    [seconds] => 27
)

答案 1 :(得分:2)

我在我的一个项目中使用类似于this的解决方案。您可以像这样使用它:

ago(strtotime("next sunday"))但您需要将$difference = $now - $time;更改为$difference = $time - $now;

答案 2 :(得分:1)

这是一个解决方案:

http://jsfiddle.net/foxbunny/xBE7L/

它也会每秒自动更新。

编辑:我已经包含了offset参数,您可以根据需要使用它来提供用户和服务器时区之间的差异。