How to compare date string using javascript

前端 未结 3 1479
醉梦人生
醉梦人生 2021-01-23 22:46

I have the following string value of a date, Sun Apr 07 2019 00:00:00 GMT-0300, and I need to compare with the following date form

3条回答
  •  一向
    一向 (楼主)
    2021-01-23 23:15

    Convert all the values to Date objects and compare those. Use a framework/library to do it, because parsing strings to dates manually has lots of places where it can go wrong.

    Currently you are comparing the literal Strings. Because neither "2019-04-08T03:00:00.000Z", nor "2019-04-13T03:00:00.000Z" match "Sun Apr 07 2019 00:00:00 GMT-0300 (Horário Padrão de Brasília)", your second if statement fails.

提交回复
热议问题