2016-07-11 23 views
0

Ich muss dieses Datum Format konvertieren: Fr 29. Juli 2016 00:00:00 GMT + 0100 (Maroc (heure d'été)) (Ich nicht, wie wir es nennen von der Weg) zu ISO-Format (JJJJ-MM-TT 00: 00: 00.000) mit Javascript Vielen Dank im VorausKonvertieren Zeitformat in ISO-Format

+0

Mögliche Duplikat [Formatierung isodate von MongoDB] (http://stackoverflow.com/questions/11486779/formatting-isodate-from-mongodb). Der Mogodb-Teil der verknüpften Frage ist irrelevant. Die Lösung ist die gleiche. – Turnip

Antwort

1

Hier ist Beispielschnipsel für Ihre Abfrage. Ich hoffe, es hilft bei Ihrer Anfrage.

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('-'); 
} 
+0

Das funktioniert gut :) –

1

Mit moment.js:

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