Divide hours from minutes into a given time value

I am currently working on a simple Time-Manager app for Android devices. My problem: I am getting the time value (similar to this -> 6:51 ) from the server. Now I want to separate the hours and minutes and I want the value to be constantly updated .

I've already looked at joda-time but can't find anything that could solve my problem, if there is a solution at all in joda-time.

Should I try to extract numbers and construct my own time format from them or is there a better and simpler solution? In case you recommend me to extract the numbers, how to solve the problem with the clock above 9.

Thanks for the help and sorry for the bad english.

+3


source to share


5 answers


Divide the time.



 String time="6:51"              //which is from server;
 String splitTime[]=time.split(":");
 String hours=splitTime[0];
 String minutes=splitTime[1];

      

+3


source


If the string you have is in format hh:mm

, you can use String.split

to separate them.



String arr [] = time.split(":");

      

+1


source


Are you getting the time from the server as a String "6:51"

?

org.joda.time.LocalTime # parse (String) will help you. LocalTime represents time without date. After parsing the String, you should be able to call the methods getHourOfDay,getMinuteOfHour

.

+1


source


Just parse the time value as a String and use split to separate the hours and minutes. Then you can convert it to int again for future use.

String Time = (String) time;
String Hour=time.split(":")[0];
String Minute=time.split(":")[1];
//If you want to use Hour and Minute for calculation purposes:
int hour=Integer.parseInt(Hour);
int minute=Integer.parseInt(Minute);

      

Shouldn't be a problem if the clock> 9

0


source


In Joda-Time 2.5.

LocalTime localTime = LocalTime.parse( "6:51" );
int hour = localTime.getHourOfDay();
int minute = localTime.getMinuteOfHour();

      

0


source







All Articles