Created
May 4, 2015 14:18
-
-
Save johanhalse/2bfbc4a14fa10c59f883 to your computer and use it in GitHub Desktop.
Small shim for formatting Pikaday dates as YYYY-MM-DD without moment.js
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
// Would be ridiculous to pull in the entire moment.js library for this | |
window.moment = function(dateString) { | |
var date = new Date(dateString); | |
var format = function() { | |
return date.getFullYear() + '-' + | |
('0' + (date.getMonth() + 1)).slice(-2) + '-' + | |
('0' + date.getDate()).slice(-2); | |
}; | |
return { | |
format: format, | |
toDate: format | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I use this, it works visually (as in the date is displayed in a nice format in the input field). But if you get the value from the field, it isn't a dateobject anymore. And you would have to parse it everytime manually again. Or am I missing something?