mrapi
mrapi

Reputation: 6033

Js new Date() creates different GMT

I'm reading data from a API server:

opTMP:
     { DATAI: "2019-10-27T00:00:00", …}
     { DATAI: "2019-10-31T00:00:00", …}

then I create a new date:

 const opTMP1 = this.opTMP.map(x => Object.assign({}, x));
  for (const op of opTMP1){ 
   let d = new Date(op.DATAI);
   console.log(d);
...
}

but in console I got different results,one is GMT+0300 and one GMT+0200 :

d: Sun Oct 27 2019 00:00:00 GMT+0300 (Eastern European Summer Time)
d: Thu Oct 31 2019 00:00:00 GMT+0200 (Eastern European Standard Time)

because of that I got problems when comparing it,I want to get only day month and year,no time info needed,how can I reset both to the same time or to 0:00:00?

Upvotes: 0

Views: 1181

Answers (1)

Pratik
Pratik

Reputation: 1399

Converting date to epoch time is good way to comparing the dates.

let d = new Date(op.DATAI).getTime();

Upvotes: 1

Related Questions