Java 计算两个日期之间相差天数

		{
			int y1 = 2016, m1 = 9, d1 = 29;
			int y2 = 2014, m2 = 11, d2 = 8;

			GregorianCalendar gcCalendar1 = new GregorianCalendar(y1, m1 - 1, d1);
			GregorianCalendar gcCalendar2 = new GregorianCalendar(y2, m2 - 1, d2);

			long timeMillis = gcCalendar1.getTimeInMillis() - gcCalendar2.getTimeInMillis();

			long days = timeMillis / (24 * 60 * 60 * 1000);
			System.out.println(days);

			SimpleDateFormat dftDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			System.out.println(dftDate.format(gcCalendar1.getTime()));
			System.out.println(dftDate.format(gcCalendar2.getTime()));
		}

猜你喜欢

转载自colin-davis.iteye.com/blog/2327903