Abderrazzak Talal
Abderrazzak Talal

Reputation: 43

Convert time format to iso format

I need to convert this date format : Fri Jul 29 2016 00:00:00 GMT+0100 (Maroc (heure d’été)) (I don't what do we call it by the way ) to iso format (yyyy-mm-dd 00:00:00.000 ) using javascript Thanks in advance

Upvotes: 0

Views: 152

Answers (2)

Michał Perłakowski
Michał Perłakowski

Reputation: 92501

Using moment.js:

moment(new Date("Fri Jul 29 2016 00:00:00 GMT+0100")).format("Y-MM-DD HH:mm:ss.SSS")

Upvotes: 1

Jatin
Jatin

Reputation: 670

Here is sample snippet for your query. I hope it helps for your query.

    function formatDate(date) {
    var d = new Date("Fri Jul 29 2016 00:00:00 GMT+0100"),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

    if (month.length < 2) month = '0' + month;
    if (day.length < 2) day = '0' + day;

    return [year, month, day].join('-');
}

Upvotes: 1

Related Questions