import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; /** * 测试日期类 * */ public class TestCalendr { public static void main(String[] args) { Calendar c = new GregorianCalendar(); c.set(2015, 8, 16, 12, 12, 12); //@1 三种形式设置时间 // c.set(Calendar.YEAR, 2015); //@2 // c.set(Calendar.MONTH, 8); // c.set(Calendar.DATE, 16); //c.set(Calendar.DAY_OF_MONTH, 16); //c.setTime(new Date()); // @3 设置为当前时间 Date d = c.getTime(); System.out.println(d); //测试日期计算 c.add(Calendar.DATE, 30); System.out.println(c); } }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)