java transformation of various formats time stamp string

private static String[] parsePatterns = {"yyyy-MM-dd","yyyy年MM月dd日",
"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd",
"yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyyMMdd"};

public static Date parseDate(String string) {
if (string == null) {
return null;
}
try {
return DateUtils.parseDate(str, parsePatterns);
} catch (ParseException e) {
return null;
}
}

 

 

ParseDate modulation method may be determined, you need to determine other formats added parsePatterns on the line.
----------------
Disclaimer: This article is CSDN blogger "Fujiwara tofu shop -" original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/wanderlustLee/article/details/88221736

 

Guess you like

Origin www.cnblogs.com/woshixiangshang/p/11417483.html