提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用日历类创建和设置日期
import java.text.SimpleDateFormat;/*nowjava - 时 代 Java*/ import java.util.Calendar; public class Main { public static void main(String[] args) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); // Set the date to 01/01/2010:12:00 cal2.set(2010, 0, 1, 12, 0); System.out.println(formatDate(cal1) + " before " + formatDate(cal2) + "? " + cal1.before(cal2));// 来 自 nowjava System.out.println(cal2.compareTo(cal1)); } public static String formatDate(Calendar cal) { SimpleDateFormat simpleFormatter =