Java SQL Date From toSqlDateString(java.sql.Date d, String pattern)

Here you can find the source of toSqlDateString(java.sql.Date d, String pattern)

Description

to Sql Date String

License

Open Source License

Declaration

public static String toSqlDateString(java.sql.Date d, String pattern) 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;

public class Main {

    public static String toSqlDateString(java.sql.Date d, String pattern) {

        String rs = "";

        try {//  ww w. j a  v  a2s  . c  om
            SimpleDateFormat formatter = new SimpleDateFormat(pattern);
            rs = formatter.format(d);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return isFirstStartDate(rs) ? "" : rs;

    }

    private static boolean isFirstStartDate(String strDate) {
        if (strDate.compareTo("1970-01-01") == 0 || strDate.compareTo("1899-12-30") == 0
                || strDate.compareTo("1969-12-31") == 0) {
            return true;
        }
        return false;
    }
}

Related

  1. toSqlDate(String dateStr, String format)
  2. toSQLDate(String dt)
  3. toSQLDate(String sDate, String format)
  4. toSqlDateFromStrDate(String p_strDate)
  5. toSqlDateJdbcEscape(final String str)