Saturday, 18 March 2017

convert date from thu jun 09 2011 00:00:00 gmt+0530 (india standard time) to yyyy-mm-dd in JavaScript.

convert date in javascript


Description:

In this example we explain that how to convert date from Thu Jun 09 2016 00:00:00 GMT+0530(India Standard Time) to YYYY-MM-DD format using JavaScript. Or how can I convert the time format “THU Jun 09 2016 00:00:00 GMT+0530(India Standard Time)” to YYYY-MM-DD in JavaScript.

So to convert the date using the Date constructor then split out the individual time components like using below function code
Code:

function converttoDate(str) {
    var date = new Date(str),
        mnth = ("0" + (date.getMonth()+1)).slice(-2),
        day  = ("0" + date.getDate()).slice(-2);
    return [ date.getFullYear(), mnth, day ].join("-");
}

converttoDate ("Thu Jan 08 2016 00:00:00 GMT+0530 (India Standard Time)");
//-> "2016-01-08"


0 comments:

Post a Comment