我需要在Java中解析两个HH:MM
格式的字符串:
String time1="10:45";
String time2="02:30";
最佳答案
愚蠢但简单:
String time1 = "10:45";
String time2 = "02:30";
String[] split1 = time1.split(":");
String[] split2 = time2.split(":");
int total = 60 * Integer.parseInt(split1[0]) +
Integer.parseInt(split1[1]) +
60 * Integer.parseInt(split2[0]) +
Integer.parseInt(split2[1]);
int hours = total / 60;
int minutes = total - hours * 60;
System.out.println(hours + ":" + minutes);
关于java - 如何从字符串中解析持续时间并添加它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11775974/