Skip to content

Instantly share code, notes, and snippets.

@johanhalse
Created May 4, 2015 14:18
Show Gist options
  • Save johanhalse/2bfbc4a14fa10c59f883 to your computer and use it in GitHub Desktop.
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
// 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
}
};
@33mhz
Copy link

33mhz commented Jun 30, 2016

Agreed!

@El4a
Copy link

El4a commented Dec 9, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment