倒数至特定日期 [英] Countdown to a specific date

查看:106
本文介绍了倒数至特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做的事情看起来应该很简单,但事实证明这很棘手.我需要一个倒计时脚本,该脚本使用目标日期并给我三个独立的数字-即该日期的天,小时和分钟-然后可以将其插入相应位置的页面中.我尝试了jCountdown,但是尽管它具有高度可定制性,但我仍然无法获得所需的东西.我想

What I'm trying to do seems like it should be simple but is proving tricky. I need a countdown script that uses a target date and gives me three separate figures - namely Days, Hours and Minutes to that date - that I can then plug into the page in the appropriate place. I tried jCountdown but while it is highly customisable I still haven't managed to get what I need. I'd like to

我可以用php来做到这一点,但我真的不想将php组合成一个已经有一些jquery的静态html页面.试图使事情尽可能简单.

I can do it with php but I don't really want to combine php into a static html page that already has some jquery in there. Trying to keep things as simple as possible.

我想要的是用户能够在后端代码中指定日期,然后提供三个单独的读数-到该日期的天数,小时数或分钟数.并非每个都合计,而是说3天3小时5分钟.

What I want is for the user to be able to specify a date in the backend code that will then give three separate readouts - the number of days, hours or minutes to that date. Not a total of each but say 3 days, 3 hours and 5 minutes.

我已经看过这个

http://jsfiddle.net/McdSV/

再次具有每个总数,无论是天,小时等,并且仍将其作为一个打印输出.似乎是我发现的一个始终如一的问题.

which again has a total number of each, whether it is days, hours, etc. and still gives it as one printout. Seems to be a consistent problem that I am finding.

任何指导将不胜感激.

推荐答案

您应该可以自己进行数学运算并将其打印出来.使用模数以分钟为单位得到余数,然后为天数取底.
在示例中,您通过减去两个时间对象而获得秒数,因此让我们从那里开始:
totalseconds%60,秒的余数
totalseconds/60,总计分钟
总分钟数%60,剩余的分钟数
等等...

You should be able to do the math yourself and print it out. Use modulus to get the remainder in minutes and then floor the days.
In the example you get seconds by subtracting the two time objects so lets start there:
totalseconds % 60, remainder of seconds
totalseconds / 60, total minutes
totalminutes % 60, remainder of minutes
etc...

查看代码: http://jsfiddle.net/jHVnz/

这篇关于倒数至特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆