Created
February 9, 2012 19:18
-
-
Save storborg/1782196 to your computer and use it in GitHub Desktop.
Reconfigure the bootstrap datepicker to use a different date format globally.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
/* Update date_input plugin so that MM/DD/YYYY format is used. */ | |
$.extend($.fn.datepicker.defaults, { | |
parse: function (string) { | |
var matches; | |
if ((matches = string.match(/^(\d{2,2})\/(\d{2,2})\/(\d{4,4})$/))) { | |
return new Date(matches[3], matches[1] - 1, matches[2]); | |
} else { | |
return null; | |
} | |
}, | |
format: function (date) { | |
var | |
month = (date.getMonth() + 1).toString(), | |
dom = date.getDate().toString(); | |
if (month.length === 1) { | |
month = "0" + month; | |
} | |
if (dom.length === 1) { | |
dom = "0" + dom; | |
} | |
return month + "/" + dom + "/" + date.getFullYear(); | |
} | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment