Convert Calendar to java.sql.Date


import java.util.Calendar;

public class Main {
  public static void main(String[] args) {
    int year = 2009;
    int month = 0; // January
    int date = 1;

    Calendar cal = Calendar.getInstance();
    cal.clear();

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, date);

    java.sql.Date sqlDate = new java.sql.Date(cal.getTimeInMillis());
    System.out.println(sqlDate);
  }
}

Output:


2009-01-01
Home 
  Java Book 
    Runnable examples  

Date Convert:
  1. Convert Calendar to java.sql.Date
  2. Convert day of year to day of month
  3. Convert java.util.Date to java.sql.Time after calculation
  4. Convert java.util.Date to java.sql.Date after calculation
  5. Convert java.util.Date to java.sql.Date
  6. Convert Date into milliseconds
  7. Convert date to GMT
  8. Convert day of the year to date
  9. Convert milliseconds to readable string
  10. Elapsed time in hours/minutes/seconds
  11. Convert longs (time_t in UNIX terminology) to seconds