//计算月数
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Calendar beginCal = Calendar.getInstance();
Calendar endCal = Calendar.getInstance();
Date begin = null;
Date end = null;
try {
begin = sdf.parse(beginTime);
beginCal.setTime(begin);
end=sdf.parse(endTime);
endCal.setTime(end);
} catch (Exception e) {
e.printStackTrace();
}
int months=(endCal.get(Calendar.YEAR)-beginCal.get(Calendar.YEAR))*12+(endCal.get(Calendar.MONTH)-beginCal.get(Calendar.MONTH))+1;
//获取当前时间
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String date = df.format(new Date());// new Date()为获取当前系统时间,也可使用当前时间戳
网友评论