Java Parse Date Pattern YYYY parseToDate(String date, String format)

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

Description

parse To Date

License

Apache License

Declaration

public static Date parseToDate(String date, String format) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date parseToDate(String date, String format) throws ParseException {
        if (date == null)
            return null;
        Date dDate = null;/*from www.j  a va 2s. co m*/
        if (format != null) {
            DateFormat formater = new SimpleDateFormat(format);
            dDate = formater.parse(date);
        } else {
            DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
            dDate = formater.parse(date);
        }

        return dDate;
    }
}

Related

  1. parseStringToDatePrettyPrint(Date date)
  2. parseStringToUtilDate(String strDate)
  3. parseTIPPDate(String dateString)
  4. parseToDate(final String date, final String format)
  5. parseToDate(String date)
  6. parseToDateLenient(final String date, final String format, final boolean lenient)
  7. parseToGregorianCalendar(String dateString)
  8. parseToRegExcel(String raw)
  9. parseToString(Date date)