need to compare the user entered time in editbox with the current time, I'm using HH:MM format not using seconds or milliseconds.
Asked
Active
Viewed 38 times
-1
-
It’s always a good idea to search the Internet and Stack Overflow before posting a question. You’re likely to find one or more good answers faster that way. When you end up posting a question, please also explain what your search brought up and how it fell short of answering your question. This will help us know more precisely what you are missing, leading to better, preciser answers. – Ole V.V. Sep 15 '18 at 08:45
-
Sorry about that, i'll keep this in mind next time – Tharun Eniyan Sep 15 '18 at 09:06
-
It’s OK. We’re all learning how we can best use this site. – Ole V.V. Sep 15 '18 at 09:07
2 Answers
0
There's two way to do this:
You can convert HH:MM format to minutes, convert current time to minutes and compare.
Or you can split HH:MM at : and compare HH given by user to HH of current time and same for MM.

Paragoumba
- 88
- 1
- 10
0
You could do like this:
int hour = Integer.parseInt(YourHourEdit.getText().toString());
int minute = Integer.parseInt(YourMinuteEdit.getText().toString());
Calendar cal = Calendar.getInstance(Locale.getDefault());
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE,minute);
Date inputDate = cal.getTime(); //get user input date
Date currentDate = Calendar.getInstance(Locale.getDefault()).getTime(); //get current date
if(inputDate.after(currentDate)){
//compare two dates and do something
}

navylover
- 12,383
- 5
- 28
- 41