public static Calendar modify(Calendar calendar, int dateField, ModifyType modifyType) {
		// 上下午特殊处理
		if (Calendar.AM_PM == dateField) {
			boolean isAM = DateUtil.isAM(calendar);
			switch (modifyType) {
			case TRUNCATE:
				calendar.set(Calendar.HOUR_OF_DAY, isAM ? 0 : 12);
				break;
			case CEILING:
				calendar.set(Calendar.HOUR_OF_DAY, isAM ? 11 : 23);
				break;
			case ROUND:
				int min = isAM ? 0 : 12;
				int max = isAM ? 11 : 23;
				int href = (max - min) / 2 + 1;
				int value = calendar.get(Calendar.HOUR_OF_DAY);
				calendar.set(Calendar.HOUR_OF_DAY, (value < href) ? min : max);
				break;
			}
		}

		// 当用户指定了无关字段时，降级字段
		if (ArrayUtil.contains(ignoreFields, dateField)) {
			return modify(calendar, dateField + 1, modifyType);
		}

		for (int i = Calendar.MILLISECOND; i > dateField; i--) {
			if (ArrayUtil.contains(ignoreFields, i) || Calendar.WEEK_OF_MONTH == i) {
				// 忽略无关字段（WEEK_OF_MONTH）始终不做修改
				continue;
			}

			if (Calendar.WEEK_OF_MONTH == dateField) {
				// 在星期模式下，月的处理忽略之
				if (Calendar.DAY_OF_MONTH == i) {
					continue;
				} else if (Calendar.DAY_OF_WEEK_IN_MONTH == i) {
					// 星期模式下，星期几统一用DAY_OF_WEEK处理
					i = Calendar.DAY_OF_WEEK;
				}
			} else if (Calendar.DAY_OF_WEEK_IN_MONTH == i) {
				// 非星期模式下，星期处理忽略之
				// 由于DAY_OF_WEEK忽略，自动降级到DAY_OF_WEEK_IN_MONTH
				continue;
			}

			modifyField(calendar, i, modifyType);
		}
		return calendar;
	}
public static Calendar modify ( Calendar calendar , int dateField , ModifyType modifyType ) { if ( Calendar . AM_PM == dateField ) { boolean isAM = DateUtil . isAM ( calendar ) ; switch ( modifyType ) { case TRUNCATE : calendar . set ( Calendar . HOUR_OF_DAY , isAM ? 0 : 12 ) ; break ; case CEILING : calendar . set ( Calendar . HOUR_OF_DAY , isAM ? 11 : 23 ) ; break ; case ROUND : int min = isAM ? 0 : 12 ; int max = isAM ? 11 : 23 ; int href = ( max - min ) / 2 + 1 ; int value = calendar . get ( Calendar . HOUR_OF_DAY ) ; calendar . set ( Calendar . HOUR_OF_DAY , ( value < href ) ? min : max ) ; break ; } } if ( ArrayUtil . contains ( ignoreFields , dateField ) ) { return modify ( calendar , dateField + 1 , modifyType ) ; } for ( int i = Calendar . MILLISECOND ; i > dateField ; i -- ) { if ( ArrayUtil . contains ( ignoreFields , i ) || Calendar . WEEK_OF_MONTH == i ) { continue ; } if ( Calendar . WEEK_OF_MONTH == dateField ) { if ( Calendar . DAY_OF_MONTH == i ) { continue ; } else if ( Calendar . DAY_OF_WEEK_IN_MONTH == i ) { i = Calendar . DAY_OF_WEEK ; } } else if ( Calendar . DAY_OF_WEEK_IN_MONTH == i ) { continue ; } modifyField ( calendar , i , modifyType ) ; } return calendar ; }
修改日期

@param calendar {@link Calendar}
@param dateField 日期字段，既保留到哪个日期字段
@param modifyType 修改类型，包括舍去、四舍五入、进一等
@return 修改后的{@link Calendar}