How to get the given date string format(pattern) in java?

后端 未结 10 1681
抹茶落季
抹茶落季 2020-11-30 04:41

I want to get the format of a given date string.

Example: I have a string like 2011-09-27T07:04:21.97-05:00 and the date format of this string is

10条回答
  •  情歌与酒
    2020-11-30 05:12

    If I understand you correctly, you want to parse arbitrary strings (that is, string of a format you don't know) as dates by using DateFormat.parse()? Then you have to deal with issues like how to handle 01-02-03 (2 Jan 2003? 1 Feb 2003? etc.)

    You should know at least something about the expected format, like a choice of several predefined formats for your input.

提交回复
热议问题