Countdown based on MySQL entry

2019-09-10 12:20发布

I have a database that logs the date and time a song was played in a format like 2011-04-13 17:55:46. It also logs the length of the song in milliseconds. How would I make a live countdown for the user to see as well as a refresh countdown?

1条回答
劳资没心,怎么记你
2楼-- · 2019-09-10 12:27

For Javascript, you can use the Date() object created from a string with the given time (you can print it to the screen in a hidden input, span, or whatever). I assume the end time is when the song ends. You can calculate this very simply based on the difference between the play time and the song length. When you say "refresh countdown," do you mean if they refresh the page? Well, I'm not sure how the song would keep playing at the given time, but you could check that the song was started and use the time you have above and do your calculation again.

查看更多
登录 后发表回答