提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用日历的before方法比较日期时间
import java.util.Calendar; public class Main { /** from N o w J a v a . c o m - 时 代 Java**/ public static void main(String[] args) { Calendar old = Calendar.getInstance(); old.set(Calendar.YEAR, 1990); Calendar now = Calendar.getInstance(); System.out.println("Is old before now ? : " + old.before(now)); } }