package cn.handan;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
public class DayDemo {
public static void main(String[] args) throws ParseException {
String str1 = "2013-4-25";
String str2 = "2013年4月15日";
int style_1 = DateFormat.MEDIUM;
int style_2 = DateFormat.LONG;
int days = getdays(str1, str2, style_1, style_2);
System.out.println(days);
}
public static int getdays(String str1, String str2, int style_1, int style_2)
throws ParseException {
DateFormat df1 = DateFormat.getDateInstance(style_1);
DateFormat df2 = DateFormat.getDateInstance(style_2);
Date date_1 = df1.parse(str1);
Date date_2 = df2.parse(str2);
long time1 = date_1.getTime();
long time2 = date_2.getTime();
long time = Math.abs(time1 - time2);
time = time / 1000 / 3600 / 24;
return (int) time;
}
}
求写 try catch 的类型,谢谢了
|
|