Countdown to a specific date

2019-02-27 13:19发布

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

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.

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.

I've taken a look at this

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.

Any guidance would be appreciated.

3条回答
Animai°情兽
2楼-- · 2019-02-27 13:36
Melony?
3楼-- · 2019-02-27 13:58

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...

See for code: http://jsfiddle.net/jHVnz/

查看更多
Summer. ? 凉城
4楼-- · 2019-02-27 13:58

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

查看更多
登录 后发表回答