I wrote a function of time in the evening, and here we summarize
Package Com.zz.bridge.impl;import Java.text.dateformat;import Java.text.parseexception;import Java.text.simpledateformat;import java.util.calendar;/** * Test class * Copyright June 9, 2015 * created by TXXS * All right Reserve D */public class Bridgetest {public static void main (String args[]) {DateFormat df = new SimpleDateFormat ("Yyyymm");//Get CAL Endar instance Calendar currenttime = Calendar.getinstance (); Calendar comparetime = Calendar.getinstance (); try { //convert string to date type Currenttime.settime (Df.parse ("201406")), Comparetime.settime (Df.parse ("201506"));} catch ( ParseException e) {//TODO auto-generated catch Blocke.printstacktrace ();} Use the Calendar method to compare the size if (Currenttime.compareto (Comparetime) > 0) { System.out.println ("The former time is small");} Else{system.out.println ("Behind Time");} Converted to a number after the comparison size int startTime = Integer.parseint ("201406"); int endTime = Integer.parseint ("201506"); System.out.println (Endtime-starttime);}}
Java String Type time comparison size