Convert Calendar to Date in Java
Description
The following code shows how to convert Calendar to Date.
Example
/* ww w . j a v a2s. co m*/
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.util.Date utilDate = cal.getTime();
System.out.println(utilDate);
}
}
The code above generates the following result.