自己写个类吧
可以写个addMinute(int minutes)的方法判别是否大过60分则进位

解决方案 »

  1.   

    //该方法要求时间用“:”分隔,如果你必须用“小时”,“分”的形式,可以再做一次转换操作。
    public class addTime  
    {
    public static void main(String[] args) 
    {
    String time1="2:45";
    String time2="0:55";
    String time3="";
    try
    {
    time3=testAddTime(time1,time2);
    }
    catch(NumberFormatException ex)
    {
    System.out.println("time format Error!");
    return;
    }
    System.out.println(time3);
    }
    static String testAddTime(String time1,String time2) throws NumberFormatException
    {
    if(time1.indexOf(":")<0||time2.indexOf(":")<0)
    {
    throw new NumberFormatException("Time Format Error!");
    }
    String[] time1s=time1.split(":");
    String[] time2s=time2.split(":");
    String result="";
    try
    {
    result=Integer.toString(Integer.parseInt(time1s[0])+Integer.parseInt(time2s[0])+
       (Integer.parseInt(time1s[1])+Integer.parseInt(time2s[1]))/60);
    result+=":"+Integer.toString((Integer.parseInt(time1s[1])+Integer.parseInt(time2s[1]))%60);
    }
    catch(NumberFormatException exx)
    {
    throw new NumberFormatException("Time Format Error!");
    }
    return result;
    }
    }