Determine if a String is a valid date before parsing

后端 未结 12 1710
半阙折子戏
半阙折子戏 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 11:52

    Use regular expressions to parse your string. Make sure that you keep both regex's pre-compiled (not create new on every method call, but store them as constants), and compare if it actually is faster then the try-catch you use.

    I still find it strange that your method returns null if both versions fail rather then throwing an exception.

提交回复
热议问题