/    Sign up×
Community /Pin to ProfileBookmark

Start timer with mention time and date using js

Hello all,

I have been trying to get the timer set with the mention date and time.
Below is the code i tried so far.

[CODE]<html>
<head>
<title></title>
</head>
<body onload=”timer();”>
<script type=”text/javascript”>
function timer() {
var now = new Date();
var outStr = now.getHours()+’:’+now.getMinutes()+’:’+now.getSeconds();
document.getElementById(‘clockDiv’).innerHTML=outStr;
setTimeout(‘timer()’,1000);
}
timer();
</script>
<div id=”clockDiv”></div>
</body>
</html>[/CODE]

The above code gives the output of system date but i want to specify the date and the timer should start from that day itself.

Example: I tried adding date and time in the new date() as below:

[CODE]var now = new Date(‘Wed, 15 May 2013 13:05:32’);[/CODE]

But then the timer doesn’t work.

Could someone please help me out here?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@daveyerwinJun 19.2016 — [CODE]

<html>
<head>
<title></title>
</head>
<body>
<span id=dv></span>
<script type="text/javascript">
(function(){
var then = new Date('Wed, 15 May 2013 13:05:32');
var start = new Date();
(function timer() {
var dif = new Date(+then + (+new Date() - +start));

dv.innerHTML = new Date(dif) ;
setTimeout(timer,1000);
})()})();
</script>
</body>
</html>


[/CODE]
×

Success!

Help @RoysonSilva 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 5.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...