Reputation: 23
I am working on a very simple app that will let user to pick starting time( using time picker) and the ending time. So essentially I want to be able to get those values (starting and ending values) and then calculate the interval so something happens during that specified period the users set.
Please, your help will be highly appreciated.
Thanks in advance.
Upvotes: 2
Views: 4589
Reputation: 56
To calculate the interval between two times that the user has selected simply use a function such as calcDifTime() in a setOnTimeChangedListener. This listener is then set to the TimePicker via setOnTimeChangedListener(). Then when a user changes the time, the listener will be called.
TimePicker timeStart;
TimePicker timeEnd;
int calcDifTime() {
int difHour = timeEnd.getCurrentHour() - timeStart.getCurrentHour();
int difMin = timeEnd.getCurrentMinute() - timeStart.getCurrentMinute();
return difHour * 60 + difMin;
}
Upvotes: 2
Reputation: 33792
A link to a time picker tutorial
and how to diff time. This is enough to get you going.
Upvotes: 0