Instant plusMillis() method in Java with Examples
The plusMillis() method of Instant class adds specified duration in milliseconds to this instant and returns the result as an instant object. This returned Instant is immutable.
Syntax:
public Instant plusMillis(long millisToAdd)
Parameters: This method accepts one parameter millisToAdd which is milliseconds to add.
Returns: This method returns Instant with the milliseconds added to it.
Exception: This method throws following exceptions:
- DateTimeException: if the result exceeds the maximum or minimum instant.
- ArithmeticException: if numeric overflow occurs.
Below programs illustrate the plusMillis() method:
Program 1:
// Java program to demonstrate // Instant.plusMillis() method import java.time.*; public class GFG { public static void main(String[] args) { // create a Instant object Instant instant = Instant.parse("2018-12-30T19:34:50.63Z"); // addition of 8800000 MILLI_OF_SECOND // means 8800 seconds to this instant Instant returnedValue = instant.plusMillis(8800000); // print result System.out.println("Returned Instant: " + returnedValue); } } |
Program 2:
// Java program to demonstrate // Instant.plusMillis() method import java.time.*; public class GFG { public static void main(String[] args) { // create a Instant object Instant instant = Instant.now(); // current Instant System.out.println("Current instant: " + instant); // addition of 420000 MILLI_OF_SECOND // means 420 seconds to this instant Instant returnedValue = instant.plusMillis(420000); // print result System.out.println("Returned Instant: " + returnedValue); } } |
References: https://docs.oracle.com/javase/10/docs/api/java/time/Instant.html#plusMillis(long)
Recommended Posts:
- Duration plusMillis(long) method in Java with Examples
- Instant with() Method in Java with Examples
- Instant from() method in Java with Examples
- Instant get() method in Java with Examples
- Instant until() Method in Java with Examples
- Instant now() Method in Java with Examples
- Instant plus() method in Java with Examples
- Instant parse() method in Java with Examples
- Instant ofEpochSecond() Method in Java with Examples
- Instant query() Method in Java with Examples
- Instant getEpochSecond() method in Java with Examples
- Instant ofEpochMilli() method in Java with Examples
- Instant plusSeconds() method in Java with Examples
- Instant toString() method in Java with Examples
- Instant range() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


