Java SQL Date Parse stringToSQLDate(String pstrValue, String pstrDateFormat)

Here you can find the source of stringToSQLDate(String pstrValue, String pstrDateFormat)

Description

String convert to SQLDate.

License

Apache License

Return

a java.sql.Date representatio of the given date string and format string.

Declaration

public static java.sql.Date stringToSQLDate(String pstrValue, String pstrDateFormat) throws ParseException 

Method Source Code

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

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

import java.util.Date;

public class Main {
    /**/*from  w ww.j a v a  2 s . c o m*/
     * String convert to SQLDate.
     * 
     * @return a java.sql.Date representatio of the given date string and format
     *         string.
     */
    public static java.sql.Date stringToSQLDate(String pstrValue, String pstrDateFormat) throws ParseException {
        if ((pstrValue == null) || (pstrValue.equals(""))) {
            return null;
        }
        Date dttTempDate = stringToDate(pstrValue, pstrDateFormat);
        return new java.sql.Date(dttTempDate.getTime());
    }

    /**
     * Convert string to Date
     * 
     * @return a java.util.Date object converted.
     */
    public static Date stringToDate(String pstrValue, String pstrDateFormat) {
        if ((pstrValue == null) || (pstrValue.equals(""))) {
            return null;
        }
        Date dttDate = null;
        try {
            SimpleDateFormat oFormatter = new SimpleDateFormat(pstrDateFormat);
            dttDate = oFormatter.parse(pstrValue);
            oFormatter = null;
        } catch (Exception e) {
            return null;
        }

        return dttDate;
    }
}

Related

  1. stringToDate(String str)
  2. StringToDateHMS(String str)
  3. stringToSqlDate(String data)
  4. stringToSqlDate(String date)
  5. stringToSqlDate(String dateVal)
  6. stringToSqlDate(String str)
  7. StrToDate(String Formate, String date)
  8. strToDate(String str)
  9. strToDate(String strDate, String formator)