Here you can find the source of parseDate(String value, Class targetType, String... formats)
public static Date parseDate(String value, Class targetType, String... formats)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; public class Main { public static Date parseDate(String value, Class targetType, String... formats) {/* w w w. j a v a2 s. co m*/ for (String format : formats) { try { long v = new SimpleDateFormat(format).parse(value) .getTime(); return (Date) targetType.getConstructor(long.class) .newInstance(v); } catch (ParseException e) { } catch (Exception e) { throw new RuntimeException(e); } try { return (Date) targetType.getConstructor(String.class) .newInstance(value); } catch (Exception e) { } } throw new IllegalArgumentException("cannot parse:" + value + " for date by formats:" + Arrays.asList(formats)); } }