Date.prototype.getPadded24Hours = function() { 
  hours = this.getHours();
  if(this.getAMPMHour == 'PM') { hours += 12; }
  return Date.padded2(hours); 
}
Date.prototype.getPaddedSeconds = function() { return Date.padded2(this.getSeconds()); }

Date.prototype.toFormattedString = function(include_time){
  str = this.getFullYear() + '-' + Date.padded2(this.getMonth() + 1) + '-' + Date.padded2(this.getDate());
  if (include_time) { str += ' ' + this.getPadded24Hours() + ':' + this.getPaddedMinutes() + ':' + this.getPaddedSeconds(); }
  return str;
}

Date.parseFormattedString = function (string) {
  // Mysql DateTime
  // http://dev.mysql.com/doc/refman/5.0/en/datetime.html
  // YYYY-MM-DD HH:MM:SS
  // YY-MM-DD HH:MM:SS
  // YYYY-MM-DD
  // YY-MM-DD
  var regexp = "([0-9]{2})?[0-9]{2}\-[0-9]{2}\-[0-9]{2} *([0-2][0-9]\:[0-5][0-9]\:[0-5][0-9])?";
  var d = string.match(new RegExp(regexp, "i"));

  if (d==null) { return new Date(); } // Return todays date

  var ymd = new Array('','','');
  var hms = new Array('00','00','00');
  if(d[2] == null) { // Time not being used
    ymd = d[0].split('-');
  } else { // Time is being used
    var dt = d[0].split(' ');
    ymd = dt[0].split('-');
    hms = dt[1].split(':');
  }
  
  return new Date(ymd[0], parseInt(ymd[1])-1, ymd[2], hms[0], hms[1], hms[2]);
}
