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
Java Book
Runnable examples
Date Convert:
- Convert Calendar to java.sql.Date
- Convert day of year to day of month
- Convert java.util.Date to java.sql.Time after calculation
- Convert java.util.Date to java.sql.Date after calculation
- Convert java.util.Date to java.sql.Date
- Convert Date into milliseconds
- Convert date to GMT
- Convert day of the year to date
- Convert milliseconds to readable string
- Elapsed time in hours/minutes/seconds
- Convert longs (time_t in UNIX terminology) to seconds