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
If you don't have anything against using libraries, you could just use the Moments.js library like so:
var now = new Date(); var dateString = moment(now).format('YYYY-MM-DD'); var dateStringWithTime = moment(now).format('YYYY-MM-DD HH:mm:ss');