1

I am trying to patch my form with the existing date object, but that date "object" is saved in Firebase as a string :

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

I console.log date when I submit the form and see it appear as:

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

So AFAIK I must convert it to that shape before patching the form. How do I do that? Especially "Thu Sep" confuses me. Also note, that I will use different languages in the Datepicker.

UPDATE:

Looks like I managed to make the Date object, but it's value is very wrong:

  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.
13
  • Try new Date(this.initialValue.dateFrom).toISOString() Commented Sep 22, 2017 at 11:32
  • @Swoox - thanks, but no changes Commented Sep 22, 2017 at 11:34
  • Wait what format are you trying to get? Commented Sep 22, 2017 at 11:40
  • I am trying now. Maybe your method works, just need to use it correctly. I need format Thu Sep 28 2017 00:00:00 GMT+0300 (EEST) Commented Sep 22, 2017 at 11:42
  • 1
    @Swoox - :-) Thanks, worked like a charm! Commented Sep 22, 2017 at 11:47

1 Answer 1

1

As you wish.

Change this:

  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]);

Into:

new date(this.initialValue.dateFrom);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.