javascript - using setTimeout to execute function excatly at specified time -


here code below..

settimeout(executequery, 5000); 

iam aware executequery run after 5 second... want run @ e.gethours()+':'+e.getminutes() console.log(e.gethours()+':'+e.getminutes()); display 1:30 ,iam trying run a function today @ 1:30 anyways fix this???

set date , time when want run function using new date(year, month, day, hours, minutes, seconds, milliseconds); . current new date() , , substract difference in milliseconds count, assign settimeout function. see following snippet:-

 window.onload=function(){   var date1=new date();   var date2=new date(2014,05,27,11,45,00);   var diff=date2.gettime()-date1.gettime();   settimeout(executequery, diff);   }  function executequery(){   alert("hello");   } 

fiddle


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -