How to parse dates in multiple formats using SimpleDateFormat

前端 未结 12 1659
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 08:41

I am trying to parse some dates that are coming out of a document. It would appear users have entered these dates in a similar but not exact format.

here are the for

12条回答
  •  轮回少年
    2020-11-22 09:23

    I was having multiple date formats into json, and was extracting csv with universal format. I looked multiple places, tried different ways, but at the end I'm able to convert with the following simple code.

    private String getDate(String anyDateFormattedString) {
        @SuppressWarnings("deprecation")
        Date date = new Date(anyDateFormattedString);
        SimpleDateFormat dateFormat = new SimpleDateFormat(yourDesiredDateFormat);
            String convertedDate = dateFormat.format(date);
        return convertedDate;
    }
    

提交回复
热议问题