Here you can find the source of parseDate(String str, boolean strict, String... parsePatterns)
Parameter | Description |
---|---|
str | the date/time string to be parsed |
strict | when true, parsing is strict |
parsePatterns | date patterns |
public static Date parseDate(String str, boolean strict, String... parsePatterns)
//package com.java2s; /*!// w ww . j ava 2s . c o m * mifmi-commons4j * https://github.com/mifmi/mifmi-commons4j * * Copyright (c) 2015 mifmi.org and other contributors * Released under the MIT license * https://opensource.org/licenses/MIT */ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { /** * Parse a date/time string with multiple patterns. * Locale is used Locale.US. * TimeZone is used UTC. * * @param str the date/time string to be parsed * @param strict when true, parsing is strict * @param parsePatterns date patterns * @return a date parsed from the string */ public static Date parseDate(String str, boolean strict, String... parsePatterns) { return parseDate(str, strict, null, null, parsePatterns); } /** * Parse a date/time string with multiple patterns. * * @param str the date/time string to be parsed * @param strict when true, parsing is strict * @param timeZone the TimeZone of date/time. Locale.US if argument is null * @param locale the Locale of date/time. UTC if argument is null * @param parsePatterns date patterns * @return a date parsed from the string */ public static Date parseDate(String str, boolean strict, TimeZone timeZone, Locale locale, String... parsePatterns) { if (str == null || str.isEmpty()) { return null; } if (parsePatterns == null || parsePatterns.length == 0) { throw new IllegalArgumentException(); } if (locale == null) { locale = Locale.US; } if (timeZone == null) { timeZone = TimeZone.getTimeZone("UTC"); } for (String parsePattern : parsePatterns) { DateFormat dateFormat = new SimpleDateFormat(parsePattern, locale); dateFormat.setTimeZone(timeZone); dateFormat.setLenient(!strict); try { return dateFormat.parse(str); } catch (ParseException e) { continue; } } return null; } }