Java
[Java] 문자열 시분초 -> 초단위로 변환(timeToSec) 구현
jn4624
2021. 10. 15. 19:22
반응형
public static int timeToSec(String time) {
String[] times = time.split(":");
int hours = Integer.parseInt(times[0]);
int minutes = Integer.parseInt(times[1]);
int seconds = Integer.parseInt(times[2]);
int totalSeconds = (+hours) * 60 * 60 + (+minutes) * 60 + (+seconds);
return totalSeconds;
}
반응형