Java Instant minus() methodThe minus() method of Java Instant class is used to return a copy of this instant with the specified amount subtracted. The Instant minus() method consists of 2 type of parameters:
The minus(TemporalAmount amountToSubtract) method returns an Instant, based on this one, with the specified amount subtracted. The amount is typically Duration but may be any other type implementing the TemporalAmount interface. The minus(long amountToSubtract, TemporalUnit unit) returns an Instant, based on this one, with the amount in terms of the unit subtracted. If it is not possible to subtract the amount, because the unit is not supported or for some other reason, an exception is thrown. SyntaxParametersamountToSubtract - the amount to subtract, not null amountToSubtract - the amount of the unit to subtract from the result, may be negative. unit - the unit of the amount to subtract, not null. ReturnAn Instant based on this instant with the subtraction made, not null An Instant based on this instant with the specified amount subtracted, not null. ExceptionsDateTimeException - if the subtraction cannot be made ArithmeticException - if numeric overflow occurs DateTimeException - if the subtraction cannot be made UnsupportedTemporalTypeException - if the unit is not supported ArithmeticException - if numeric overflow occurs Example 1Output: The output will be like this. 2017-02-03T10:27:30Z Example 2Output: The output will be like this. 2014-08-25T10:15:30Z Example 3Output: The output will be like this. 2014-12-03T10:15:30Z Example 4Output: The output will be like this. 2014-12-03T10:15:33Z Example 5Output: The output will be like this. 2017-05-01T20:57:43.045Z Nanos > 2017-05-01T20:57:43.044999990Z Micros > 2017-05-01T20:57:43.044990Z Millis > 2017-05-01T20:57:43.035Z Seconds > 2017-05-01T20:57:33.045Z Minutes > 2017-05-01T20:47:43.045Z Hours > 2017-05-01T10:57:43.045Z HalfDays > 2017-04-26T20:57:43.045Z Days > 2017-04-21T20:57:43.045Z -- Weeks not supported -- Months not supported -- Years not supported -- Decades not supported -- Centuries not supported -- Millennia not supported -- Eras not supported -- Forever not supported Examples Java Instant minus(long amountToSubtract, TemporalUnit unit) MethodExample 6Output: The output will be like this. 2014-08-25T10:15:30Z Example 7Output: The output will be like this. 2017-02-03T05:37:30Z Next TopicJava-instant-issupported-method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India