Java SQL Date Convert DateToSQLDate(Date pDate)

Here you can find the source of DateToSQLDate(Date pDate)

Description

Date To SQL Date

License

Open Source License

Declaration

public static java.sql.Date DateToSQLDate(Date pDate) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DF_YMD = "yyyy-MM-dd";
    public static final String DF_HMS = "HH:mm:ss";

    public static java.sql.Date DateToSQLDate(Date pDate) {
        java.sql.Date dd = new java.sql.Date(pDate.getTime());
        //      SimpleDateFormat   sdf   =   new   SimpleDateFormat(DF_YMDHMS);   
        //        System.out.println(sdf.format(dd));  
        return dd;
    }//from   w  ww .  j  av  a  2s .  c om

    public static String getTime() {
        return dateToString(now(), DF_HMS);
    }

    public static String getTime(Date trialTime) {
        return dateToString(trialTime, DF_HMS);
    }

    public static String dateToString(Date date, String format) {
        if (date == null) {
            return "";
        }
        synchronized (date) {
            SimpleDateFormat df = new SimpleDateFormat(format);
            return df.format(date);
        }
    }

    public static String dateToString(Date date) {
        return dateToString(date, DF_YMD);
    }

    public static Date now() {
        return new Date();
    }
}

Related

  1. dateToInternal(java.sql.Date date)
  2. dateToLong(Date date)
  3. dateToSql(Date dat)
  4. dateToSqlDate(Date date)
  5. dateToSqlDate(Date date)
  6. dateToSQLDate(java.util.Date d)
  7. dateToStamp(String date)
  8. dateToSTR(Date data, String formato)
  9. dateToStr(java.util.Date date)