比较两个时分秒时间的大小

public static boolean compTime(String s1,String s2){
		try {
			if (s1.indexOf(":")<0||s1.indexOf(":")<0) {
				System.out.println("格式不正确");
			}else{
				String[]array1 = s1.split(":");
				int total1 = Integer.valueOf(array1[0])*3600+Integer.valueOf(array1[1])*60+Integer.valueOf(array1[2]);
				String[]array2 = s2.split(":");
				int total2 = Integer.valueOf(array2[0])*3600+Integer.valueOf(array2[1])*60+Integer.valueOf(array2[2]);
				return total1-total2>0?true:false;
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			return true;
		}
		return false;

	}

发布了87 篇原创文章 · 获赞 22 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/gaofenglxx/article/details/60140067