Determine if a String is a valid date before parsing

后端 未结 12 1658
半阙折子戏
半阙折子戏 2020-12-03 11:36

I have this situation where I am reading about 130K records containing dates stored as String fields. Some records contain blanks (nulls), some contain strings like this: \'

12条回答
  •  执笔经年
    2020-12-03 12:00

    Don't be too hard on yourself about using try-catch in logic: this is one of those situations where Java forces you to so there's not a lot you can do about it.

    But in this case you could instead use DateFormat.parse(String, ParsePosition).

提交回复
热议问题