Saturday, October 4, 2025
HomeLanguagesJavaOffsetTime isAfter() method in Java with examples

OffsetTime isAfter() method in Java with examples

The isAfter() method of OffsetTime class in Java formats checks if the passed time is after the specified time in the parameter.

Syntax:

public boolean isAfter(OffsetTime other)

Parameter: This method accepts a single mandatory parameter other which specifies the time to be compared with.

Return Value: It returns true if the date is after the passed date, else it return false.

Below programs illustrate the isAfter() method:

Program 1 :




// Java program to demonstrate the isAfter() method
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Parses the time
        OffsetTime time1
            = OffsetTime.parse("15:30:30+07:00");
  
        // Parses the time
        OffsetTime time2
            = OffsetTime.parse("15:20:30+07:00");
  
        // prints the time1
        System.out.println("time1: "
                           + time1);
  
        // prints the time2
        System.out.println("time1: "
                           + time2);
  
        System.out.println("time1 is after time2: "
                           + time1.isAfter(time2));
    }
}


Output:

time1: 15:30:30+07:00
time1: 15:20:30+07:00
time1 is after time2: true

Program 2 :




// Java program to demonstrate the isAfter() method
  
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Parses the time
        OffsetTime time1
            = OffsetTime.parse("15:30:30+07:00");
  
        // Parses the time
        OffsetTime time2
            = OffsetTime.parse("15:30:30+07:00");
  
        // prints the time1
        System.out.println("time1: "
                           + time1);
  
        // prints the time2
        System.out.println("time1: "
                           + time2);
  
        System.out.println("time1 is after time2: "
                           + time1.isAfter(time2));
    }
}


Output:

time1: 15:30:30+07:00
time1: 15:30:30+07:00
time1 is after time2: false

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#isAfter-java.time.OffsetTime-

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32332 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6704 POSTS0 COMMENTS
Nicole Veronica
11868 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6819 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS