代码如下:
//得到当前时间String nowDate = getDate(new Date());
//特定的输入时间
String startDate = mP_startdateText.getText().toString().trim();
// 将日期转换为毫秒数进行比较
long specificNowDateMilliseconds = specificTimeFormat(nowDate);
System.out.println("nowDate"+nowDate);
System.out.println("startdate"+startDate);
if (startDate.length() > 0 && startDate != null && startDate != "") {
specificStartdateMilliseconds = specificTimeFormat(startDate);
if (specificNowDateMilliseconds >= specificStartdateMilliseconds) {
//获取时间段的天数
bingcheng = DateTools.getIntervalDays(startDate, nowDate);
String newNowDate = nowDate.replace('-', '/');
String newstartDate = startDate.replace('-', '/');
//时间段相差
String diffValue=DurationFormatUtils.formatPeriod(new Date(newstartDate).getTime(), new Date(newNowDate).getTime(), "y-M-d");
String[] yearMonthDayValueArr = diffValue.split("-");
String year=yearMonthDayValueArr[0];
String month=yearMonthDayValueArr[1];
String day=yearMonthDayValueArr[2];
//_PatientInfo.setmP_bingcheng(bingcheng + "天");
StringBuilder builder=new StringBuilder();
builder.append(year).append("年").append(month).append("月").append(day).append("天");
_PatientInfo.setmP_bingcheng(builder.toString());
_PatientInfo.setmP_startdate(startDate);
saveData(_PatientInfo);