JAVA计算两个日期相差月数

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
java.lang.Math;

	int result = 0;

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	Calendar c1 = Calendar.getInstance();
	Calendar c2 = Calendar.getInstance();

            //起始时间
	c1.setTime(sdf.parse("2012-11-12"));
            //结束时间
	c2.setTime(sdf.parse( "2012-12-12"));

            result = c2.get(Calendar.YEAR)*12 - c1.get(Calendar.YEAR) *12;
            result = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH) + result;
            int day = c2.get(Calendar.DAY_OF_MONTH) - c1.get(Calendar.DAY_OF_MONTH);
            result = result + (day >= 0 ? 0 : -1);

	return result;
上一篇:公开课 redis系列二----五大类型的使用场景


下一篇:【逆向&编程实战】Metasploit中的安卓载荷凭什么吊打SpyNote成为安卓端最强远控