compare dates in String format

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

    your approach is good because yyyy-mm-dd hh:ii:ss can be compared as a string and get correct results, other date formats will fail

    another option is to read this stackoverflow question

    How to compare dates in Java?

    and you should simply parse your strings and create Date or Calendar objects, depends on what you want to do , below is something I find useful

    http://www.mkyong.com/java/java-how-to-get-current-date-time-date-and-calender/

提交回复
热议问题