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.
source to share
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
.
source to share
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
source to share