java 根据类名示例化类
即时类minusSeconds()方法 (Instant Class minusSeconds() method)
minusSeconds() method is available in java.time package.
minusSeconds()方法在java.time包中可用。
minusSeconds() method is used to subtract the given duration in seconds from this Instant and returns the Instant.
minusSeconds()方法用于从此Instant减去给定的持续时间(以秒为单位),并返回Instant。
minusSeconds() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
minusSeconds()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
minusSeconds() method may throw an exception at the time of performing subtraction.
minusSeconds()方法在执行减法时可能会引发异常。
ArithmeticException: This exception may throw when the calculated result value exceeds the limit.
ArithmeticException :当计算结果值超过限制时,可能引发此异常。
Syntax:
句法:
public Instant minusSeconds(long sec_val);
Parameter(s):
参数:
long sec_val – represents the seconds to be subtracted from this Instant.
long sec_val –表示要从此Instant减去的秒数。
Return value:
返回值:
The return type of this method is Instant, it returns the Instant that holds the value subtracted the given duration in seconds from this Instant.
此方法的返回类型为Instant ,它返回Instant,该Instant保存从该Instant中减去给定持续时间的值(以秒为单位)。
Example:
例:
// Java program to demonstrate the example
// of minusSeconds(long sec_val) method
// of Instant
import java.time.*;
public class MinusSecondsOfInstant {
public static void main(String args[]) {
long seconds = 5;
// Instantiates two Instant
Instant ins1 = Instant.parse("2006-04-03T05:10:15.60Z");
Instant ins2 = Instant.now();
// Display ins1,ins2 and seconds
System.out.println("Instant ins1 and ins2: ");
System.out.println("ins1: " + ins1);
System.out.println("ins2: " + ins2);
System.out.println("seconds to subtract: " + seconds);
System.out.println();
// Here, this method subtracts the given duration
// in seconds from this Instant ins1
// i.e. here we are subtracting the
// given 5 seconds from this ins1
Instant minus_sec = ins1.minusSeconds(seconds);
// Display minus_sec
System.out.println("ins1.minusSeconds(seconds): " + minus_sec);
// Here, this method subtracts the given duration
// in seconds from this Instant ins2
// i.e. here we are subtracting the given
// 5 seconds from this ins2
minus_sec = ins2.minusSeconds(seconds);
// Display minus_sec
System.out.println("ins2.minusSeconds(seconds): " + minus_sec);
}
}
Output
输出量
Instant ins1 and ins2:
ins1: 2006-04-03T05:10:15.600Z
ins2: 2020-05-26T23:43:43.735769Z
seconds to subtract: 5
ins1.minusSeconds(seconds): 2006-04-03T05:10:10.600Z
ins2.minusSeconds(seconds): 2020-05-26T23:43:38.735769Z
翻译自: https://www.includehelp.com/java/instant-minusseconds-method-with-example.aspx
java 根据类名示例化类