I have a date with the format Sun May 11,2014. How can I convert it to 2014-05-11 using JavaScript?
Sun May 11,2014
2014-05-11
No library is needed
Just pure JavaScript.
The example below gets the last two months from today:
var d = new Date() d.setMonth(d.getMonth() - 2); var dateString = new Date(d); console.log('Before Format', dateString, 'After format', dateString.toISOString().slice(0,10))