Here you can find the source of parseStringToDate(String dateString)
public static java.util.Date parseStringToDate(String dateString)
//package com.java2s; /******************************************************************************* * Copyright (c) 2008 Ariadne Foundation. * //ww w . j a v a 2s . c om * This file is part of Ariadne Harvester. * * Ariadne Harvester is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Ariadne Harvester is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Ariadne Harvester. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ import java.text.ParseException; public class Main { public static java.util.Date parseStringToDate(String dateString) { java.text.SimpleDateFormat dfparser; dateString = dateString.replaceAll("th", ""); dateString = dateString.replaceAll("nd", ""); dateString = dateString.replaceAll("\\n", " "); dateString = dateString.replaceAll("\\r", " "); dateString = dateString.replaceAll( System.getProperty("line.separator"), " "); // Replace 2 or more spaces by 1 space, because otherwise the parsing // will fail. dateString = dateString.replaceAll("\\s{2,}", " "); try { // The one used by the LOM Java API dfparser = new java.text.SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss z", java.util.Locale.US); return dfparser.parse(dateString); } catch (ParseException e) { // } try { // The one used by java.util.Date toString method dfparser = new java.text.SimpleDateFormat( "EEE MMM dd HH:mm:ss zzz yyyy", java.util.Locale.US); return dfparser.parse(dateString); } catch (ParseException e) { // } try { dfparser = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'"); return dfparser.parse(dateString); } catch (ParseException e) { // } try { dfparser = new java.text.SimpleDateFormat("yyyy-MM-dd"); return dfparser.parse(dateString); } catch (ParseException e) { // } try { dfparser = new java.text.SimpleDateFormat("MMM dd, yyyy"); return dfparser.parse(dateString); } catch (ParseException e) { // } try { dfparser = new java.text.SimpleDateFormat("MM-dd.yy"); return dfparser.parse(dateString); } catch (ParseException e) { // } try { dfparser = new java.text.SimpleDateFormat("dd MMM yyyy"); return dfparser.parse(dateString); } catch (ParseException e) { // } try { dfparser = new java.text.SimpleDateFormat("dd.MM.yy"); return dfparser.parse(dateString); } catch (ParseException e) { // } try { dfparser = new java.text.SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); return dfparser.parse(dateString); } catch (ParseException e) { // } try { dfparser = new java.text.SimpleDateFormat( "E M dd hh:mm:ss z yyyy"); return dfparser.parse(dateString); } catch (ParseException e) { // } // If all attempts fail, just return null. return null; } }