Skip to main content
gamedev.net
🔒 Locked

[JavaScript] Execute function at given time

Started by Telastyn Dec 8, 2011 at 8:32 PM 3 replies 1.3k views
Original Post
Telastyn
Telastyn
I have a relatively simple problem at first glance that I suspect has a really slick solution that I don't know about, and don't particularly have the time to hunt through google'd libraries for:

In javascript, I need to trigger a specified anonymous function at a given UTC time. What's a good way to get that done?

Though I'm familiar with a number of the concepts, I don't have a lot of experience with the language or its idioms/libraries. Thanks in advance.
dmatter
dmatter
Just to throw an idea down, you could probably use setTimeout which will execute your function after a specified delay. It's then just a matter of calculating the 'delay' between now till your desired time in UTC.
Telastyn
Telastyn

Where exactly is this javascript executing?


In a programatically generated webpage on the local filesystem being browsed to by the WebBrowser control in .NET, set to force IE9 compatibility mode.
Antheus
Antheus
b = new Date("UTC time");
a = new Date();

delta = b.getTime() - a.getTime();

setTimeout(foo, delta);


Syntax might be a bit off.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.