compare dates in String format

后端 未结 10 1323
时光说笑
时光说笑 2021-02-12 16:30

I\'m getting two dates as String values and I wanted to check start time is earlier than the end time. I compare them as it is without converting them to date using Simple

10条回答
  •  独厮守ぢ
    2021-02-12 17:13

    It is not good practice and a code smell.

    You lose semantic correct and readable code. (and extensibility, timezones, and the other right things, that already had been said)

    You don't want to compare two Strings, you want to compare 2 Dates - so just do this, compare two Date objects.

    If you create unit-tests and test your comparing method, you will never write a method that compares 2 "string"-dates correctly in every case, without converting them to dates.

提交回复
热议问题