package com.zz.bridge.impl; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; /** * 测试类 * Copyright 2015年6月9日 * created by txxs * all right reserved */ public class BridgeTest { public static void main(String args[]){ DateFormat df = new SimpleDateFormat("yyyyMM"); //获取Calendar实例 Calendar currentTime = Calendar.getInstance(); Calendar compareTime = Calendar.getInstance(); try { //把字符串转成日期类型 currentTime.setTime(df.parse("201406")); compareTime.setTime(df.parse("201506")); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } //利用Calendar的方法比较大小 if (currentTime.compareTo(compareTime) > 0) { System.out.println("前者时间小"); }else{ System.out.println("后边时间大"); } //转成数字后比较大小 int startTime = Integer.parseInt("201406"); int endTime = Integer.parseInt("201506"); System.out.println(endTime-startTime); } }