JavaScript Javascript Countdown shows NaN in IE and Firefox, works in Chrome

I'm working on a site for a client where he needs a countdown timer to count down to 10pm two days from each site update. (or however many days he wishes to enter) The countdown functions perfectly in Google Chrome but in Internet Explorer and Firefox it shows NaN NaN. I've read this means "not a number" so is there something wrong with the way my code in calculating the date information? Any help would be appreciated! My code is below:

<span id="countdown1" class="countdown"></span>
     <script language="javascript">

     // set the date we're counting down to 2 days from now at 10pm
var target_date1 = Date.parse("2014-01-05 22:00:00:000");

// variables for time units
var days1, hours1, minutes1, seconds1;

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

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

// find the amount of "seconds" between now and target
var current_date1 = new Date().getTime();
var seconds_left1 = (target_date1 - current_date1) / 1000;

// do some time calculations
days1 = parseInt(seconds_left1 / 86400);
seconds_left1 = seconds_left1 % 86400;

hours1 = parseInt(seconds_left1 / 3600);
seconds_left1 = seconds_left1 % 3600;

minutes1 = parseInt(seconds_left1 / 60);
seconds1 = parseInt(seconds_left1 % 60);

// format countdown string + set tag value
countdown1.innerHTML = days1 + " days, " + hours1 + " hours, "
+ minutes1 + " minutes, " + seconds1 + " seconds";  

}, 1000);
</script>
Answer:1

Your date format won't work in Firefox (and apparently IE). This:

Date.parse("2014-01-05 22:00:00:000")

is NaN in Firefox. Firefox likes dates like "Dec 31, 2013" or ISO dates like "2011-10-10T14:48:00". More information at MDN.

Answer:2

Use a RFC2822 or ISO 8601 date format for what you pass to Date.parse() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

Answer:3

I am using linux and phantomjs to test some javascript var page = require('webpage').create(); var fs = require('fs'); var address = system.args[1]; page.onConsoleMessage = ...

I am using linux and phantomjs to test some javascript var page = require('webpage').create(); var fs = require('fs'); var address = system.args[1]; page.onConsoleMessage = ...

  1. phantomjs command line example
  2. phantomjs command line arguments
  3. phantomjs command line
  4. phantomjs command line args
  5. phantomjs command line options
  6. phantomjs command line parameters
  7. phantomjs command line open url
  8. phantomjs command line pdf
  9. phantomjs command line timeout
  10. phantomjs.exe command line
  11. install phantomjs command line
  12. phantomjs linux command line
  13. exit phantomjs command line
  14. phantomjs windows command line
  15. phantomjs screenshot command line
  16. using phantomjs command line
  17. phantomjs proxy command line
  18. phantomjs config command line
  19. phantomjs pass arguments command line
  20. phantomjs run from command line

I have this Jquery function to mask my textbox: jQuery(function($){ //Mask textbox #hour with placeholder $("#hour").mask("9:99",{placeholder:"0"}); $("#hourInTable").mask("9:99",{placeholder:...

I have this Jquery function to mask my textbox: jQuery(function($){ //Mask textbox #hour with placeholder $("#hour").mask("9:99",{placeholder:"0"}); $("#hourInTable").mask("9:99",{placeholder:...

  1. jquery code doesn't work
  2. jquery-code-doesn't-work-on-dynamic-content-loaded-with-ajax

Could you please let me know why this code doesn't work? I put the value 1 or the value 2 in the text element but I don't get the result "this is 1" or "this is 2" respectively. It seems that the line ...

Could you please let me know why this code doesn't work? I put the value 1 or the value 2 in the text element but I don't get the result "this is 1" or "this is 2" respectively. It seems that the line ...

  1. javascript comparison function
  2. javascript comparison function sort
  3. javascript comparison function string
  4. javascript set comparison function
  5. javascript datetime comparison function
  6. javascript number comparison function
  7. javascript arrow function comparison

I have a contenteditable div like this: <form> <div name="new_post" class="post" contenteditable="true"></div> <button type="submit">Submit</button> </form>...

I have a contenteditable div like this: <form> <div name="new_post" class="post" contenteditable="true"></div> <button type="submit">Submit</button> </form>...

  1. removing everything after a character using excel
  2. removing everything after character
  3. excel removing everything after a character
  4. sed remove everything after pattern