Instant类的plusMillis()方法将此毫秒添加指定的持续时间(以毫秒为单位),并将结果作为即时对象返回。此返回的Instant是不可变的。
用法:
public Instant plusMillis(long millisToAdd)
参数:此方法接受一个参数millisToAdd,该参数要添加的毫秒数。
返回值:此方法返回Instant(加上毫秒)。
异常:此方法引发以下异常:
DateTimeException:如果结果超过最大或最小瞬间。
ArithmeticException:如果发生数字溢出。
以下示例程序旨在说明plusMillis()方法:
示例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);
}
}
示例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);
}
}
参考:https://docs.oracle.com/javase/10/docs/api/java/time/Instant.html#plusMillis(long)