java 根据类名示例化类
即时类plusSeconds()方法 (Instant Class plusSeconds() method)
plusSeconds() method is available in java.time package.
plusSeconds()方法在java.time包中可用。
plusSeconds() method is used to add the given duration in seconds to this Instant and return the Instant.
plusSeconds()方法用于将给定的持续时间(以秒为单位)添加到此Instant并返回Instant。
plusSeconds() 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.
plusSeconds()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
plusSeconds() method method may throw an exception at the time of performing addition.
plusSeconds()方法 method在执行加法时可能会引发异常。
DateTimeException: This exception may throw when this Instant value reaches out of the min or max instant.
DateTimeException :当此Instant值超出最小或最大瞬时值时,可能引发此异常。
Syntax:
句法:
public Instant plusSeconds(long sec_val);
Parameter(s):
参数:
long sec_val – represents the seconds value to add to this Instant.
long sec_val –表示要添加到此Instant的秒数。
Return value:
返回值:
The return type of this method is Instant, it returns the Instant that holds the value added the given seconds to this Instant.
此方法的返回类型为Instant ,它返回Instant,该Instant保留将给定秒数添加到此Instant的值。
Example:
例:
// Java program to demonstrate the example
// of plusSeconds(long sec_val) method
// of Instant
import java.time.*;
public class PlusSecondsOfInstant {
public static void main(String args[]) {
long seconds = 25;
// 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 add: " + seconds);
System.out.println();
// Here, this method adds the given duration
// in seconds with this Instant ins1
// i.e. here we are adding the given
// 25 seconds with this ins1
Instant plus_sec = ins1.plusSeconds(seconds);
// Display plus_sec
System.out.println("ins1.plusSeconds(seconds): " + plus_sec);
// Here, this method adds the given duration
// in seconds with this Instant ins2
// i.e. here we are adding the given
// 25 seconds with this ins2
plus_sec = ins2.plusSeconds(seconds);
// Display plus_sec
System.out.println("ins2.plusSeconds(seconds): " + plus_sec);
}
}
Output
输出量
Instant ins1 and ins2:
ins1: 2006-04-03T05:10:15.600Z
ins2: 2020-05-27T00:25:09.640174Z
seconds to add: 25
ins1.plusSeconds(seconds): 2006-04-03T05:10:40.600Z
ins2.plusSeconds(seconds): 2020-05-27T00:25:34.640174Z
翻译自: https://www.includehelp.com/java/instant-plusseconds-method-with-example.aspx
java 根据类名示例化类