Java SQL Date Create convertToSDate(java.util.Date uDate)

Here you can find the source of convertToSDate(java.util.Date uDate)

Description

convertToSDate

Chuyen ngay kieu java.util.Date thanh java.sql.Date

License

Apache License

Parameter

Parameter Description
uDate java.util.Date

Return

sDate - java.sql.Date hoac null

Declaration

public static java.sql.Date convertToSDate(java.util.Date uDate) 

Method Source Code

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

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

public class Main {
    /**/*from   w  ww.ja  v a  2 s  .c  o  m*/
     * <h1>convertToSDate</h1> Chuyen ngay kieu java.util.Date thanh
     * java.sql.Date
     * 
     * @param uDate
     *            java.util.Date
     * @return sDate - java.sql.Date hoac null
     */
    public static java.sql.Date convertToSDate(java.util.Date uDate) {
        if (uDate == null) {
            return null;
        } else {
            java.sql.Date sDate = new java.sql.Date(uDate.getTime());
            return sDate;
        }
    }

    /**
     * <h1>convertToSDate</h1> Chuyen String dinh dang "dd/MM/yyyy" thanh ngay
     * kieu java.sql.Date
     * 
     * @param dateInString
     *            String
     * @return uDate - java.sql.Date hoac null
     */
    public static java.sql.Date convertToSDate(String dateInString) {
        if (dateInString == null) {
            return null;
        } else {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
            java.util.Date uDate = null;
            java.sql.Date sDate = null;
            try {
                uDate = dateFormat.parse(dateInString);
                sDate = new java.sql.Date(uDate.getTime());
            } catch (ParseException e) {
                return null;
            }
            return sDate;
        }
    }
}

Related

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