convert string in unknown format to date in c#

前端 未结 4 1245
你的背包
你的背包 2021-01-13 06:45

I have searched stackoverflow for an answer but no luck. I am developing a windows application and I have some strings in different date formats, eg.

dd/MM/y         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 07:33

    If you are processing some import file with a lot of dates in the same unknown format, you could try different formats and hope there is exactly one that doesn't give format errors.

    Or to put it another way: split the "dates" into three numbers and check the range of values for each of those numbers. Values > 1900 will be years. If you find values from 1 to 31, those will be days. Values from 1 to 12 might be months, but could also be days. Try and identify each of the parts.

    The best way is to ask the supplier of those dates for the format.

提交回复
热议问题