Determine if a String is a valid date before parsing

后端 未结 12 1646
半阙折子戏
半阙折子戏 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

    Looks like three options if you only have two, known formats:

    • check for the presence of - or / first and start with that parsing for that format.
    • check the length since "dd-MMM-yy" and "dd/MM/yyyy" are different
    • use precompiled regular expressions

    The latter seems unnecessary.

提交回复
热议问题