Here you can find the source of isDateFormatString(String s, String dateFormat, Locale locale)
Parameter | Description |
---|---|
s | a parameter |
dateFormat | a parameter |
locale | a parameter |
public static boolean isDateFormatString(String s, String dateFormat, Locale locale)
//package com.java2s; /*/*ww w .j a v a 2s . c o m*/ * OpenClinica is distributed under the * GNU Lesser General Public License (GNU LGPL). * For details see: http://www.openclinica.org/license * copyright 2003-2005 Akaza Research */ import java.text.SimpleDateFormat; import java.util.Locale; public class Main { /** * Return true if a string can be parsed by the dateFormat with locale. * * @param s * @param dateFormat * @param locale * @return */ //ywang (Oct., 2011) public static boolean isDateFormatString(String s, String dateFormat, Locale locale) { String dateformat = parseDateFormat(dateFormat); SimpleDateFormat f = new SimpleDateFormat(dateformat, locale); f.setLenient(false); try { f.parse(s); return true; } catch (Exception ex) { return false; } } /** * return dateFormat with lowercase "y" and "d" * * @param dateFormat * @return */ public static String parseDateFormat(String dateFormat) { String s = dateFormat; while (s.contains("Y")) { s = s.replace("Y", "y"); } while (s.contains("D")) { s = s.replace("D", "d"); } return s; } }