compare dates in String format

后端 未结 10 1375
时光说笑
时光说笑 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:05

    Yes, it is better to convert the String to Date and compare.

    1. It ensures they are actually valid dates so no 20-20-2012.
    2. Once the conversion is complete only a single number comparison remains.
    3. It allows for great flexibility when comparing dates of different formats.
    4. The alternative is writing code that parses each number and compares it to the other, which is just as much work.

提交回复
热议问题