Java SQL Date Create convertToMySqlDate(Date date)

Here you can find the source of convertToMySqlDate(Date date)

Description

convert To My Sql Date

License

Open Source License

Declaration

public static java.sql.Date convertToMySqlDate(Date date) 

Method Source Code


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

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static java.sql.Date convertToMySqlDate(Date date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = dateFormat.format(date);

        System.out.println(strDate);

        java.sql.Date sqlDate;//w  w  w.  j  av  a2  s .  co  m
        try {
            sqlDate = new java.sql.Date(dateFormat.parse(strDate).getTime());
            System.out.println(strDate);

            return sqlDate;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }

    }
}

Related

  1. convertSqlUtil(java.util.Date d)
  2. convertStringToSql(final String dateStr)
  3. convertToCalendar(Date date)
  4. convertToDatabaseDate(Date date)
  5. convertToDate(Object o)
  6. convertToSDate(java.util.Date uDate)
  7. convertToSqlDate(Calendar calendar)
  8. convertToSqlDate(java.util.Date argUtilDate)
  9. ConvertToSqlDate(java.util.Date date)