Here you can find the source of convertDate(String date, String[] formats)
Parameter | Description |
---|---|
date | the string to be parsed |
formats | the valid format to parse the string |
Parameter | Description |
---|
public static Date convertDate(String date, String[] formats) throws java.text.ParseException
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**//from ww w.j a va 2 s . com * This method try to parse a string into a Date object using an array with * the valid formats * * @param date * the string to be parsed * @param formats * the valid format to parse the string * @return return the Date object that represent the string * @throws java.text.ParseException */ public static Date convertDate(String date, String[] formats) throws java.text.ParseException { Date ret = null; for (String pattern : formats) { try { ret = new SimpleDateFormat(pattern).parse(date); break; } catch (java.text.ParseException e) { } } if (ret == null) throw new java.text.ParseException(date, 0); return ret; } }