Java SQL Date From toSqlDate(final Date date)

Here you can find the source of toSqlDate(final Date date)

Description

to Sql Date

License

Apache License

Declaration

public static java.sql.Date toSqlDate(final Date date) 

Method Source Code

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

import java.util.Calendar;

import java.util.Date;

public class Main {
    public static java.sql.Date toSqlDate(final int year, final int month, final int dayOfMonth) {
        return new java.sql.Date(toDate(year, month, dayOfMonth).getTime());
    }/*  w w  w  .  j ava2  s  .  c  o  m*/

    public static java.sql.Date toSqlDate(final Date date) {
        return new java.sql.Date(date.getTime());
    }

    /**
     * create Date instance.
     * @param year
     * @param month Month(start with 1)
     * @param dayOfMonth
     * @return
     */
    public static Date toDate(final int year, final int month, final int dayOfMonth) {

        return toDate(year, month, dayOfMonth, 0, 0, 0);
    }

    /**
     * create Date instance.
     * @param year
     * @param month Month(start with 1)
     * @param dayOfMonth
     * @param hour
     * @param minute
     * @param second
     * @return
     */
    public static Date toDate(final int year, final int month, final int dayOfMonth, final int hour,
            final int minute, final int second) {

        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, dayOfMonth, hour, minute, second);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
}

Related

  1. toSqlDate(Calendar calendar)
  2. toSqlDate(Date date)
  3. toSqlDate(Date date)
  4. toSqlDate(Date date)
  5. toSqlDate(Date dt)
  6. toSqlDate(final String _text, final String _dateFormat)
  7. toSQLDate(java.util.Date date)
  8. toSQLDate(java.util.Date date)
  9. toSqlDate(java.util.Date date)