0

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

  • Possible duplicate of [Formatting ISODate from Mongodb](http://stackoverflow.com/questions/11486779/formatting-isodate-from-mongodb). The Mogodb part of the linked question is irrelevant. The solution is the same. – Turnip Jul 11 '16 at 11:07

2 Answers2

1

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('-');
}
Jatin
  • 660
  • 3
  • 8
  • 28
1

Using moment.js:

moment(new Date("Fri Jul 29 2016 00:00:00 GMT+0100")).format("Y-MM-DD HH:mm:ss.SSS")
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177