Page 1 of 1

Can not get the correct output from variable.

Posted: Sun Aug 11, 2013 11:09 am
by Johnny

I don't get this to work. The local storage is working and is displaying in the codevar saam = maand +" "+ dag + " " + jaar;/code correctly. "Saam" wil output "September 10 2013".

But when I put it codevar target_date = new Date(saam).getTime();/code it is not working.

When I put it like this codevar target_date = new Date("September 10 2013").getTime();/code then it is working 100%.

code
var dag = localStorage.getItem('dag');
var maand = localStorage.getItem('maand');
var jaar = localStorage.getItem('jaar');
var saam = maand +" "+ dag + " " + jaar;
// set the date we're counting down to
var target_date = new Date(saam).getTime();

// variables for time units
var days, hours, minutes, seconds;

// get tag element
var countdown = document.getElementById("countdown");

// update the tag with id "countdown" every 1 second
setInterval(function () {

Code: Select all

 // find the amount of "seconds" between now and target 
 var current_date = new Date().getTime(); 
 var seconds_left = (target_date - current_date) / 1000; 

 // do some time calculations 
 days = parseInt(seconds_left / 86400); 
 seconds_left = seconds_left % 86400; 

 hours = parseInt(seconds_left / 3600); 
 seconds_left = seconds_left % 3600; 

 minutes = parseInt(seconds_left / 60); 
 seconds = parseInt(seconds_left % 60); 

 // format countdown string + set tag value 
 countdown.innerHTML = days + "dae, " + hours + "ure, " 
 + minutes + "maande, " + seconds + "sekondes";   

}, 1000);
/code


Can not get the correct output from variable.

Posted: Sun Aug 11, 2013 11:45 am
by Johnny

It is working. Sorry for the question :)