Java Parse Date parseDate(String date, String format)

Here you can find the source of parseDate(String date, String format)

Description

parse Date

License

Open Source License

Declaration

public static Date parseDate(String date, String format) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    public static final String DATE_FORMAT_D = "EEE, d MMM yyyy HH:mm:ss Z";

    public static Date parseDate(String date, String format) {
        if (date == null) {
            return null;
        }/*ww w.j a  v  a  2 s.c  o  m*/
        date = date.trim();
        if (date.length() == 0) {
            return null;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        try {
            return dateFormat.parse(date);
        } catch (ParseException e) {
            //throw new RuntimeException(e);
            return null;
        }
    }

    public static Date parse(String date) throws ParseException {
        if (date == null) {
            return null;
        }
        date = date.trim();
        if (date.length() == 0) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT_D, Locale.US);
        return format.parse(date);
    }
}

Related

  1. parseDate(String date)
  2. parseDate(String date)
  3. parseDate(String date)
  4. parseDate(String date, Locale locale)
  5. parseDate(String date, String expression)
  6. parseDate(String date, String format)
  7. parseDate(String date, String format)
  8. parseDate(String date, String format)
  9. parseDate(String date, String format)