计算两个String 类型的时间相关几个月
2017-06-10 18:32
274 查看
/** * 返回两个时间段相隔几个月 * @param date1 * @param date2 * @return * @throws ParseException * @throws ParseException */ public static long getMonth(String startDate, String endDate) throws ParseException { SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); long monthday; Calendar starCal = Calendar.getInstance(); starCal.setTime(f.parse(startDate)); Calendar endCal = Calendar.getInstance(); endCal.setTime(f.parse(endDate)); monthday = ((endCal.get(Calendar.YEAR) - starCal.get(Calendar.YEAR)) * 12 + (endCal.get(Calendar.MONTH) - starCal.get(Calendar.MONTH))); if (starCal.get(Calendar.DATE) < endCal.get(Calendar.DATE)) { monthday = monthday + 1; } return monthday; }
相关文章推荐
- 计算两个String 类型的时间相关几个月
- c#如何计算两个日期相差几年几个月?C#日期间隔 c#时间间隔
- 根据指定类型计算两个日期相差的时间
- Mysql两个time类型计算时间相减
- 自定义标签实现JSP页面计算两个时间类型变量的差,返回xx天xx小时xx分钟xx秒
- 计算两个日期之间相差几天(Date类型与String类型互相转换)
- java计算一个Date(TimeStamp)与一个格式化的String类型时间的相差天数或者相差时间
- JS中String类型转换Date类型 并 计算时间差
- golang 计算两个时间的时间差
- 获取当天是星期几,计算两个日期相隔时间
- Android编程计算函数时间戳的相关方法总结
- 时间戳转换成String类型
- VS C# 获取系统当前时间+timer的作用+无法将类型“int”隐式转换为“string”;
- Oracle时间相关-(求timestamp类型的时间差)
- 15、oracle:计算两个时间的差值
- 计算两个日期的时间间隔
- php计算两个时间的差值
- 写4个同名方法,实现两个整数、两个实数,一个实数一个整数,一个整数一个实数之间的求和。在主调函数中调用这4个方法计算相关的值。(方法的重载)
- 计算两个日期之间的时间
- java中用String类型进行计算