How to get hours and minutes from a String variable ?

java, string, time

Solution

Try this way, by split() method,

String timme = "13:10";
String[] time = timme.split ( ":" );
int hour = Integer.parseInt ( time[0].trim() );
int min = Integer.parseInt ( time[1].trim() );

Problem

I have a `String timme = "13:10"`. I was wondering how would I best go about getting the hours and minutes and converting them into integers. i.e. int hours = 13 , int minute = 10. I know a for-loop wouldn't be the most efficient way, is there anything simpler?

Original source

Related problems