本文共 3918 字,大约阅读时间需要 13 分钟。
minus
Syntax:
句法:
public Instant minus(TemporalAmount t_amt); public Instant minus(long amt, TemporalUnit t_unit);
minus() method is available in java.time package.
minus()方法在java.time包中可用。
minus(TemporalAmount t_amt) method is used to subtract the given amount from this Instant and return the Instant.
minus(TemporalAmount t_amt)方法用于从此Instant减去给定数量并返回Instant。
minus(long amt, TemporalUnit t_unit) method is used to subtract the given amount in the given unit from this Instant and return the Instant.
minus(long amt,TemporalUnit t_unit)方法用于从此Instant减去给定单位的给定数量,并返回Instant。
These methods may throw an exception at the time of performing subtraction.
这些方法在执行减法时可能会引发异常。
These are non-static methods and it is accessible with class objects and if we try to access these methods with class name then we will get an error.
这些是非静态方法,可通过类对象访问,如果尝试使用类名访问这些方法,则会收到错误消息。
Parameter(s):
参数:
In the first case, "minus(TemporalAmount t_amt)",
在第一种情况下,“ minus(TemporalAmount t_amt)”,
In the second case, "minus(long amt, TemporalUnit t_unit)",
在第二种情况下,“减号(long amt,TemporalUnit t_unit)”,
Return value:
返回值:
In both the cases, the return type of the method is Instant,
在这两种情况下,方法的返回类型均为Instant 。
In the first case, it returns the Instant that holds the value subtracted the given amount from this Instant.
在第一种情况下,它返回的Instant保持从该Instant减去给定值的值。
In the second case, it returns the Instant that holds the value subtracted the given amount in unit from this Instant.
在第二种情况下,它返回的Instant保持从该Instant中减去以单位表示的给定值的值。
Example:
例:
// Java program to demonstrate the example // of minus() method of Instantimport java.time.*;import java.time.temporal.*;public class MinusOfInstant { public static void main(String args[]) { long amt = 2; // Instantiates two Instant and // a Duration object Instant ins1 = Instant.parse("2006-04-03T05:10:15.00Z"); Instant ins2 = Instant.now(); Duration du = Duration.ofSeconds(2); // Display ins1,ins2 System.out.println("Instant ins1 and ins2: "); System.out.println("ins1: " + ins1); System.out.println("ins2: " + ins2); System.out.println("amt to subtract: " + amt); System.out.println("du to subtract: " + du); System.out.println(); // Here, this method subtracts the given amount // in the given unit from this Instant i.e. here // we are subtracting 2 hours from Instant ins1 Instant minus_val = ins1.minus(amt, ChronoUnit.HOURS); // Display minus_val System.out.println("ins1.minus(amt,ChronoUnit.HOURS): " + minus_val); // Here, this method subtracts the given amount // from this Instant i.e. here we are subtracting // 2 seconds from Instant ins2 minus_val = ins2.minus(du); // Display minus_val System.out.println("ins2.minus(du): " + minus_val); }}
Output
输出量
Instant ins1 and ins2: ins1: 2006-04-03T05:10:15Zins2: 2020-05-28T01:06:04.706169Zamt to subtract: 2du to subtract: PT2Sins1.minus(amt,ChronoUnit.HOURS): 2006-04-03T03:10:15Zins2.minus(du): 2020-05-28T01:06:02.706169Z
翻译自:
minus
转载地址:http://uivzd.baihongyu.com/