Java SQL Date Create asSqlDate(String date)

Here you can find the source of asSqlDate(String date)

Description

Convert string as format "yyyy-MM-dd" to java.sql.Date.

License

Apache License

Parameter

Parameter Description
date String date.

Return

java.sql.Date object.

Declaration

public static java.sql.Date asSqlDate(String date) 

Method Source Code

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

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

public class Main {
    /**//  w  w  w . j  a va2s . c o m
     * Convert string as format "yyyy-MM-dd" to java.sql.Date.
     * 
     * @param date String date.
     * @return java.sql.Date object.
     */
    public static java.sql.Date asSqlDate(String date) {
        try {
            java.util.Date dt = new SimpleDateFormat("yyyy-MM-dd").parse(date);
            return new java.sql.Date(dt.getTime());
        } catch (ParseException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

Related

  1. asDate(java.sql.Date sqlDate)
  2. asDate(Object tsObj)
  3. asSqlDate(Date date)
  4. asSqlDate(Date date)
  5. beforeNow(final Date d)
  6. beginOfDay(Date date)
  7. castToSqlDate(Object value)
  8. convert(Date date)