Java Instant.minusMillis() Method with Examples
Tags: Java Instant Java 8
In this Java core tutorial we learn how to use the java.time.Instant.minusMillis() method to subtract number of milliseconds from an Instant object in Java programming language.
How to subtract milliseconds from Instant object in Java
In Java program, with a given Instant object we can use Instant.minusMillis(long millisToSubtract) method to return a new Instant object with number of milliseconds be subtracted as Java code below.
InstantMinusMillisExample1.java
import java.time.Instant;
public class InstantMinusMillisExample1 {
public static void main(String... args) {
Instant instant = Instant.parse("2022-07-11T08:00:30Z");
// subtract 2000 milliseconds
instant = instant.minusMillis(2000);
System.out.println(instant);
}
}
2022-07-11T08:00:28Z
Happy Coding 😊
Related Articles
Java Instant.now() Method with Examples
Java Instant.ofEpochSecond() Method with Examples
Java Instant.ofEpochMilli() Method with Examples
Java Instant.parse() Method with Examples
Java Instant.getEpochSecond() Method with Examples
Java Instant.getNano() Method with Examples
Java Instant.plusSeconds() Method with Examples
Java Instant.plusMillis() Method with Examples
Java Instant.plusNanos() Method with Examples
Java Instant.minusSeconds() Method with Examples
Java Instant.minusNanos() Method with Examples
Java Instant.atOffset() Method with Examples
Java Instant.atZone() Method with Examples
Java Instant.toEpochMilli() Method with Examples
Java Instant.compareTo() Method with Examples
Java Instant.isAfter() Method with Examples
Java Instant.isBefore() Method with Examples
Java Instant.equals() Method with Examples