Java Parse Date parseDate(String dateString)

Here you can find the source of parseDate(String dateString)

Description

parse Date

License

Open Source License

Declaration

public static Date parseDate(String dateString) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 OSSMETER Partners.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*  w  w  w  .j  a va  2s  .c  o m*/
 *    Yannis Korkontzelos - Implementation.
 *******************************************************************************/

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    static SimpleDateFormat[] sdfList = new SimpleDateFormat[] {
            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"),
            new SimpleDateFormat("dd MMM yyyy HH:mm:ss zzz"),
            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm zzz (Z)"),
            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm zzz"),
            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss"),
            new SimpleDateFormat("dd MMM yyyy HH:mm:ss"),
            new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss Z"),
            new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy") };

    public static Date parseDate(String dateString) {
        for (SimpleDateFormat sdf : sdfList) {
            ParsePosition ps = new ParsePosition(0);
            Date result = sdf.parse(dateString, ps);
            if (ps.getIndex() != 0)
                return result;
        }
        System.err.println("\t\t" + dateString + " cannot be parsed!\n");
        return null;
    }
}

Related

  1. parseDate(String dateString)
  2. parseDate(String dateString)
  3. parseDate(String dateString)
  4. parseDate(String dateString)
  5. parseDate(String dateString)
  6. parseDate(String dateString)
  7. parseDate(String dateString)
  8. parseDate(String dateString, Locale locale)
  9. parseDate(String dateString, SimpleDateFormat simpleDateFormat)