Java SQL Date Parse getSqlDateByShortStr(String dateStr)

Here you can find the source of getSqlDateByShortStr(String dateStr)

Description

get Sql Date By Short Str

License

Open Source License

Declaration

public static java.sql.Date getSqlDateByShortStr(String dateStr) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;
import java.text.DateFormat;

import java.util.Calendar;

public class Main {
    static final DateFormat YYYYMMDD_FORMAT = new java.text.SimpleDateFormat("yyyyMMdd");

    public static java.sql.Date getSqlDateByShortStr(String dateStr) {
        java.sql.Date da = null;//from  w  w w.  j a  va  2 s .com
        try {
            da = new java.sql.Date(YYYYMMDD_FORMAT.parse(dateStr).getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return da;
    }

    public static String getTime() {
        Timestamp time = new Timestamp(Calendar.getInstance().getTime().getTime());
        return time.toString();
    }
}

Related

  1. getSQLDate(String dateString)
  2. getSqlDate(String dateString, String format)
  3. getSqlDate(String str)
  4. getSqlDateFromStr(DateFormat format, String s, boolean need_default)
  5. getSQLDateFromStr(String s)
  6. getSqlDateFromString(String dateAsString, String format)
  7. parse(String date)