時間丸め処理

/**
	 * 時間丸め処理
	 * @param time 時間
	 * @param roundMinutes 丸め分数
	 * @param roundMethod 丸め方法
	 * @return 丸め後時間
	 */
	public static String timeRound(String time, Integer roundMinutes, String roundMethod) {
		// 丸め分数かどうか丸め方法が、空の場合
		if (StringUtils.isEmpty(time) || roundMinutes == null 

                        || StringUtils.isEmpty(roundMethod) || roundMinutes == 0) {

			return time;
		}
		// 時間タイプの変換
		Date timeTemp = DateUtil.convStr2Date(time, Const.DATE_FORMAT_DB_HHMM);
		// 時
		int hour = Integer.parseInt(DateUtil.convDate2Str(timeTemp, "HH"));
		// 分
		int minutes = Integer.parseInt(DateUtil.convDate2Str(timeTemp, "mm"));
		// 計算分数
		double countMin = hour * 60 + minutes;
		// 分数単位
		double unit = 0;


		// 切り上げの‘場合
		if (Const.ROUND_METHOD_UP.equals(roundMethod)) {
			// 上げの丸め
			unit = Math.ceil(countMin/roundMinutes);
		} else {
			// 捨ての丸め
			unit = Math.floor(countMin/roundMinutes);
		}


		double temp =  roundMinutes * unit / 60;


		// 丸め後、時を取得する
		hour = (int) temp;
		// 丸め後、分を取得する
		minutes = (int) Math.round(((temp - hour) * 60));


		// 丸め後、時間を設定する
		time = CommonUtil.formatLeftZero2(hour) + CommonUtil.formatLeftZero2(minutes);


		return time;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值