基于MySQL条目的倒数计时 [英] Countdown based on MySQL entry
问题描述
我有一个数据库,该数据库以2011-04-13 17:55:46这样的格式记录播放歌曲的日期和时间。它还以毫秒为单位记录歌曲的长度。我将如何进行实时倒计时以及刷新倒计时?
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?
推荐答案
对于Javascript,您可以使用从给定时间的字符串创建的 Date()
对象(您可以将其以隐藏的输入,跨度或其他方式打印到屏幕上)。我认为结束时间是歌曲结束的时间。您可以根据播放时间和歌曲长度之间的差异非常简单地进行计算。当您说刷新倒数时,是指他们是否刷新页面?好吧,我不确定这首歌在给定时间将如何继续播放,但是您可以检查歌曲是否已开始播放,并使用上面的时间重新计算。
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.
这篇关于基于MySQL条目的倒数计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!