Java SQL Date Parse getSqlDate(String dateString, String format)

Here you can find the source of getSqlDate(String dateString, String format)

Description

get Sql Date

License

Open Source License

Declaration

public static java.sql.Date getSqlDate(String dateString, String format) throws ParseException 

Method Source Code


//package com.java2s;

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;

public class Main {

    public static java.sql.Date getSqlDate(String dateString) throws ParseException, NullPointerException {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        ParsePosition pos = new ParsePosition(0);
        java.util.Date d = sdf.parse(dateString, pos);

        return new java.sql.Date(d.getTime());

    }//from w w  w . ja v  a  2 s . com

    public static java.sql.Date getSqlDate(String dateString, String format) throws ParseException {

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        ParsePosition pos = new ParsePosition(0);
        java.util.Date d = sdf.parse(dateString, pos);

        return new java.sql.Date(d.getTime());
    }
}

Related

  1. getSQLDate(String dateString)
  2. getSqlDate(String str)
  3. getSqlDateByShortStr(String dateStr)
  4. getSqlDateFromStr(DateFormat format, String s, boolean need_default)
  5. getSQLDateFromStr(String s)