json datetime format in javascript

json datetime format in javascript

function formatJSONDate(jsonDate) {
    //2014-09-05T00:00:00
    var today = new Date(jsonDate);
    var date = today.getDate();
    var month = today.getMonth() + 1; //January is 0. so we add + 1;

    if (date < 10) {
        date = '0' + date
    }
    if (month < 10) {
        month = '0' + month
    }
    var today = date + FormatMonth(month);
    return today;
}

function FormatMonth(jsonMonth) {
    var month = '';
    switch (jsonMonth) {
        case "01":
            month = "Jan";
            break;
        case "02":
            month = "Feb";
            break;
        case "03":
            month = "Mar";
            break;
        case "04":
            month = "Apr";
            break;
        case "05":
            month = "May";
            break;
        case "06":
            month = "Jun";
            break;
        case "07":
            month = "Jul";
            break;
        case "08":
            month = "Aug";
            break;
        case "09":
            month = "Sep";
            break;
        case "10":
            month = "Oct";
            break;
        case "11":
            month = "Nov";
            break;
        case "12":
            month = "Dec";
            break;

    }
    return month;

}
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

json datetime format in javascript json datetime format in javascript Reviewed by Anil Singh on 3:08 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^