Java SQL Date Parse parseSQLDate(String dateStr, String pattern)

Here you can find the source of parseSQLDate(String dateStr, String pattern)

Description

parse SQL Date

License

Apache License

Declaration

public static java.sql.Date parseSQLDate(String dateStr, String pattern) 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 final static String STANDARD_DATE_PATTERN = "yyyy-MM-dd";

    public static java.sql.Date parseSQLDate(String dateStr, String pattern) throws ParseException {
        Date d = parse(dateStr, pattern);
        return new java.sql.Date(d.getTime());
    }/*from   www. ja  va 2s. com*/

    public static java.sql.Date parseSQLDate(String dateStr) throws ParseException {
        Date d = parse(dateStr, STANDARD_DATE_PATTERN);
        return new java.sql.Date(d.getTime());
    }

    public static Date parse(String dateStr) {
        return parse(dateStr, STANDARD_DATE_PATTERN);
    }

    public static Date parse(String dateStr, String pattern) {

        try {
            DateFormat format = new SimpleDateFormat(pattern);
            return format.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. parseDateyyyy_MM_DD(String ds)
  2. parseSqlDate(final String value)
  3. parseSqlDate(final String value)
  4. parseSqlDate(java.util.Date date)
  5. parseSqlDate(java.util.Date date)
  6. parseString2Date(String s, SimpleDateFormat format)
  7. parseUTCDateFromString(String dt)
  8. parseUtilDateToSqlDate(Date date)
  9. stringToDate(final String dateString)