Thursday, November 20, 2025
HomeLanguagesJavaOffsetTime minusSeconds() method in Java with examples

OffsetTime minusSeconds() method in Java with examples

The minusSeconds() method of OffsetTime class in Java returns a copy of this OffsetTime with the specified Seconds in the parameter getting subtracted.

Syntax :

public OffsetTime minusSeconds(long Seconds)

Parameter: This method accepts a single parameter Seconds which the Seconds to be subtracted. It may be negative.

Return Value: It returns a OffsetTime based on this time with the Seconds subtracted and it is not null.

Below programs illustrate the minusSeconds() method:

Program 1 :




// Java program to demonstrate the minusSeconds() method
  
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
        // Parses the time
        OffsetTime time = OffsetTime.parse("11:10:10+05:05");
  
        // Specified Seconds subtracted
        System.out.println("After subtraction, time is: " 
                                   + time.minusSeconds(5));
    }
}


Output:

After subtraction, time is: 11:10:05+05:05

Program 2 :




// Java program to demonstrate the minusSeconds() method
  
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
        // Parses the time
        OffsetTime time = OffsetTime.parse("11:10:10+05:05");
  
        // Specified Seconds subtracted
        System.out.println("After subtraction, time is: " 
                                   + time.minusSeconds(-5));
    }
}


Output:

After subtraction, time is: 11:10:15+05:05

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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11927 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11995 POSTS0 COMMENTS
Shaida Kate Naidoo
6906 POSTS0 COMMENTS
Ted Musemwa
7164 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS