How to convert a date String into the right format in Java?

后端 未结 4 2060
耶瑟儿~
耶瑟儿~ 2021-01-16 16:43

Can somebody please explain to me how I can convert

2009-10-27 14:36:59.580250

into

27.10.2009, 14:36 ?

Th

4条回答
  •  滥情空心
    2021-01-16 17:24

    Check out SimpleDateFormat. You can use this to both parse and format. I would suggest parsing the above into a Date object using one SimpleDateFormat, and then formatting to a String using a 2nd SimpleDateFormat.

    Note that SimpleDateFormat suffers from threading issues, and so if you're using this in a threaded environment, either create new SimpleDateFormats rather than used static versions, or use the corresponding but thread-safe classes in Joda.

提交回复
热议问题