【无标题】

计算两个时间段相加比如0:21:10+1:01:21(当个位和十位为一位数时自动补0)

 public static String calc(String time1, String time2) {
        int temp1 = 0;
        int temp2 = 0;
        int tempa = 0;
        int tempb = 0;
        int tempq = 0;
        int tempp = 0;
        int hour = 0;
        int min = 0;
        int second = 0;
        String[] timeList1 = time1.split("[: ]+");
        String[] timeList2 = time2.split("[: ]+");
//秒
        temp1 =Integer.valueOf(timeList1[2]);
        temp2 =Integer.valueOf(timeList2[2]);
        if((temp1 +temp2)>=60)

        {
            second = temp1 + temp2 - 60;
            min++;
        } else

        {
            second = temp1 + temp2;
        }
//分
        tempa=Integer.valueOf(timeList1[1]);
        tempb =Integer.valueOf(timeList2[1]);

        if((tempa +tempb)>=60)

        {
            min =  min+tempa + tempb - 60;
            hour++;
        } else

        {
            min = min + tempa + tempb;
        }
        tempq=Integer.valueOf(timeList1[0]);
        tempp =Integer.valueOf(timeList2[0]);

        hour=hour+tempp+tempq;


        String format=null;

        String time = hour + ":" + min + ":" + second;

        String[] split1 = time.split(":");
        if(split1[2].length()<2){
            split1[2]="0"+split1[2];
        }
        if(split1[1].length()<2){
            split1[1]="0"+split1[1];
        }

        format=split1[0]+":"+split1[1]+":"+split1[2];

        return  format;

    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值