Here you can find the source of parseDate(final String date, final List
Parameter | Description |
---|---|
date | The date to convert as String. |
patterns | The date patterns to convert the String to a date-object. |
public static Date parseDate(final String date, final List<String> patterns)
//package com.java2s; /**//from www. j ava 2s . com * Copyright (C) 2007 Asterios Raptis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; public class Main { /** * Tries to convert the given String to a Date. * * @param date * The date to convert as String. * @param patterns * The date patterns to convert the String to a date-object. * @return Gives a Date if the convertion was successfull otherwise false. */ public static Date parseDate(final String date, final List<String> patterns) { for (String pattern : patterns) { final SimpleDateFormat formatter = new SimpleDateFormat(pattern); try { final Date result = formatter.parse(date); return result; } catch (final ParseException e) { // Do nothing... } } return null; } }