Compare current time Joda Time

2

I have a comparison that checks if the current time is after the configured time.

LocalTime horaConfig = new LocalTime(6, 00, 00);
LocalTime horaAtual = new LocalTime(20, 00, 00);

horaAtual.isAfter(horaConfig);

My problem is that since the current time is 8pm at night, Joda Time understands that 6am is already after 8pm. and ends up stopping my process. It's working if I put a time until 11:00 PM.

Is there any method to solve this compare problem with jodaTime?

    
asked by anonymous 12.09.2014 / 19:16

1 answer

3

LocalTime only saves the time information, does not save information of the day , therefore, 20h will always be greater than 6h.

Use DateTime instead, and enter the full date, with day , month, year, and time. Example:

import org.joda.time.DateTime;
public class MeuJoda {
    public static void main(String[] args) {
        DateTime dataConfig = DateTime.parse("2014-09-12T06:00:00Z");
        DateTime dataAtual = DateTime.parse("2014-09-11T20:00:00Z");
        System.out.println(dataAtual.isAfter(dataConfig));
    }
}

false , because in dataAtual I put 20h yesterday, and in dataConfig I put 6h today.

    
12.09.2014 / 20:01