Answers for "Compare current time with another time in Android"

0

how to compare current date and time with another date and time in android

Date date1 = calendar1.getTime();
Date date2 = calendar2.getTime();
if (date1.compareTo(date2) > 0)
{    Log.i("app", "Date1 is after Date2");} 
else if (date1.compareTo(date2) < 0) 
{    Log.i("app", "Date1 is before Date2");} 
else if (date1.compareTo(date2) == 0) 
{    Log.i("app", "Date1 is equal to Date2");}
Posted by: Guest on April-28-2020
0

how to compare time from sysytem time in android

SimpleDateFormat inputParser = new SimpleDateFormat(inputFormat, Locale.US);

private void compareDates(){
    Calendar now = Calendar.getInstance();

    int hour = now.get(Calendar.HOUR);
    int minute = now.get(Calendar.MINUTE);

    date = parseDate(hour + ":" + minute);
    dateCompareOne = parseDate(compareStringOne);
    dateCompareTwo = parseDate(compareStringTwo);

    if ( dateCompareOne.before( date ) && dateCompareTwo.after(date)) {
        //yada yada
    }
}

private Date parseDate(String date) {

    try {
        return inputParser.parse(date);
    } catch (java.text.ParseException e) {
        return new Date(0);
    }
}
Posted by: Guest on July-28-2021

Code answers related to "Compare current time with another time in Android"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language