org.apache.commons
commons-lang3
3.8
org.apache.commons.lang3.time.DateUtils
Date date = DateUtils.parseDate(strDate, “yyyy-MM-dd”,”yyyy-MM-dd HH:mm:ss”,”yyyy/MM/dd”,”yyyy/MM/dd HH:mm:ss”);
/**
* <p>Parses a string representing a date by trying a variety of different parsers.</p>
*
* <p>The parse will try each parse pattern in turn.
* A parse is only deemed successful if it parses the whole of the input string.
* If no parse patterns match, a ParseException is thrown.</p>
* The parser will be lenient toward the parsed date.
*
* @param str the date to parse, not null
* @param parsePatterns the date format patterns to use, see SimpleDateFormat, not null
* @return the parsed date
* @throws IllegalArgumentException if the date string or pattern array is null
* @throws ParseException if none of the date patterns were suitable (or there were none)
*/
public static Date parseDate(final String str, final String... parsePatterns) throws ParseException {
return parseDate(str, null, parsePatterns);
}
第一个参数是时间字符串
后面的参数都是时间格式字符串,可以添加多个
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/189170.html原文链接:https://javaforall.cn