2017-09-22 23 views
1

日付オブジェクトとして認識されない値Iは、既存のDateオブジェクトで、私のフォームにパッチを適用しようとしていますが、その日付「オブジェクト」は、文字列としてFirebaseに保存されます。角度素材 - 日付ピッカー:DateAdapter

date: "2017-09-05T21:00:00.000Z" 

私がフォームを送信し、それのように表示されたとき、私は日付をCONSOLE.LOG:だから私の知る限り、私は、フォームに修正プログラムを適用する前に、その形状に変換する必要があり

Thu Sep 28 2017 00:00:00 GMT+0300 (EEST) 

。それ、どうやったら出来るの?特に「Thu Sep」は私を混乱させます。また、私はDatepickerで異なる言語を使用することに注意してください。

UPDATE

私はDateオブジェクトを作成するために管理したように見えますが、それは価値のは非常に間違っている:

const str: string[] = this.initialValue.dateFrom.split('-'); 
    console.log(str); // ["2017", "08", "31T21:00:00.000Z"] - correct date 
    const day = str[2][0] + str[2][1]; 
    console.log(day); // 31 - correct 

    this.initialValue.dateFrom = new Date(+day, +str[1], +str[0]); 
    console.log(this.initialValue.dateFrom); // Tue Mar 09 1937 00:00:00 GMT+0200 (EET) - not correct. 
+0

'新しいDate(this.initialValue.dateFrom).toISOString()' – Swoox

+0

@Swoox試してみてください - おかげで、ない変更 –

+0

何を待っをあなたは取得しようとしていますか? – Swoox

答えて

1

あなたが望むように。

変更この:

const str: string[] = this.initialValue.dateFrom.split('-'); 
    console.log(str); // ["2017", "08", "31T21:00:00.000Z"] - correct date 
    const day = str[2][0] + str[2][1]; 
    console.log(day); // 31 - correct 

    this.initialValue.dateFrom = new Date(+day, +str[1], +str[0]); 

の中へ:

new date(this.initialValue.dateFrom); 
関連する問題