当前日期加上某一数字后的天数、两个日期之间的天数计算

	 /**
	   * 当前日期加上天数后的日期
	   * @param num 为增加的天数
	   * @return
	   */
	 public static Date plusDay2(int num){
	   Date d = new Date();
	   SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	   String currdate = format.format(d);
	   System.out.println("现在的日期是:" + currdate);

	   Calendar ca = Calendar.getInstance();
	   // 		num为增加的天数,可以改变的
	   ca.add(Calendar.DATE, num);
	   d = ca.getTime();
	   return d;
	 }

	/**
	 * 通过时间秒毫秒数判断两个时间的间隔
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static int differentDaysByMillisecond(Date date1,Date date2)
	{
		int days = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));
		return days;
	}

猜你喜欢

转载自blog.csdn.net/qq_35275233/article/details/86488120