a- package demo;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- public class CalcularTimeOfTwoDate {
- /**
- * 计算两个日期的时间间隔
- *
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- String d1 = "2015-10-1";
- String d2 = "2015-09-28";
- getTimeOfTwoDate(d1, d2);
- Calendar c = Calendar.getInstance();
- }
- private static void getTimeOfTwoDate(String d1, String d2)
- throws ParseException {
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
- Long time = Math.abs(sf.parse(d1).getTime() - sf.parse(d2).getTime());
- System.out.println((int) (time / 1000 / 3600 / 24) + "天");
- }
- }
复制代码
|
|