Skip to content

Instantly share code, notes, and snippets.

@jhammann
Created April 24, 2014 12:06
Show Gist options
  • Select an option

  • Save jhammann/11252263 to your computer and use it in GitHub Desktop.

Select an option

Save jhammann/11252263 to your computer and use it in GitHub Desktop.
If you use the great jquery countdown plugin with a datetime object from you database you may encounter some invalid date object errors in Firefox and/or IE. This code takes care of that issue by using a regex. Make sure your countdown_date string datetime is like the one used in this code.
// jquery countdown: http://keith-wood.name/countdown.html
var countdown_date = "07-05-1990 02:00";
var dateRegex = countdown_date.match(/(\d{2})-(\d{2})-(\d{4}) (.*)/);
var newDate = dateRegex[3] + "/" + dateRegex[2] + "/" + dateRegex[1] + " " + dateRegex[4];
var date = new Date(newDate);
$(".countdown-timer").countdown({until: date, format: "YODH", padZeroes: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment