java --計算當前時間以前的7天時間

工程需求: 用戶下訂單付款後,7天以內能夠退款,超過7天就退款不了 例如:用戶下訂單支付時間:20160623163600,所以用戶的退款截止日期:20160670163600java

// 邏輯
		// 1.判斷支付時間,大於7天,不予退款
		// 2.小於7天,
		//2.1 所有沒有使用/使用了部分 --生成退款單 和 退款單明細
		//2.2 所有使用 --生成退款單
		CustomerOrder customerOrder = customerOrderMapper.selectByPrimaryKey(orderId);
		//下單時間
		Long timeOutDate = Long.parseLong(customerOrder.getPayDate());
		
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
		Calendar c = new GregorianCalendar();
		java.util.Date date = new java.util.Date();
		c.setTime(date);
		c.add(Calendar.SECOND, -604800);
		java.util.Date dateBefore = c.getTime();
		String timeCurrent = df.format(dateBefore);
		Long nowDate = Long.parseLong(timeCurrent);
		
		if (timeOutDate < nowDate) {
                        //超期不容許退款
			resultObject.setResultMsg(Constant.MSG_TIMEOUT_FAILED);
			return resultObject;
		} else {
                        //退款處理
                        ……
                }
相關文章
相關標籤/搜索