/    Sign up×
Community /Pin to ProfileBookmark

Using setTime function for Timer

Hi,

Here’s some of the code:

var d = new Date();
if(!e)
e = new Date();
var tdiff = d.getTime() – e.getTime();
d.setTime(tdiff + hour*60*60*1000 + min*60*1000 + sec*1000);

So the tdiff is 0. Then I’m trying to add the offset sent by the user for hours, minutes, and seconds. The minutes and seconds are correct, but the hours is off. It always shows 18 when the hour is set to 0. Is this the proper way to accomplish this task?

Thanks!
?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JuuitchanFeb 01.2006 — Don't use Date() unless you are crazy, lazy, or forced to!

Try this:
<i>
</i>var foo=new Date();
foo.setTime(0);
// foo now contains your local equivalent
// of 1970-01-01 (Thu) 00:00 GMT
alert(foo);


Don't use Date(). Store the time as seconds, and then convert it manually, using arithmetical functions.
×

Success!

Help @OutCaster spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...