Call a javascript function at a specific time of day

前端 未结 3 1051
时光取名叫无心
时光取名叫无心 2020-11-22 16:22

for example i want to call a js function at 10.00.00.00 am how can i do?



        
3条回答
  •  [愿得一人]
    2020-11-22 17:07

    Assuming the code is located on a web page that will be loaded before 10:00 and will still be viewed at 10:00, you can use setTimeout() to set up a timed event. the function takes some JS statement to execute, and the number of milliseconds before it should execute. You can find this second part pretty easily with the built-in date functions.

提交回复
热议问题