java 根据类名示例化类_Java即时类| minusNanos()方法与示例

java 根据类名示例化类

即时类minusNanos()方法 (Instant Class minusNanos() method)

  • minusNanos() method is available in java.time package.

    minusNanos()方法在java.time包中可用。

  • minusNanos() method is used to subtract the given duration in nanoseconds from this Instant and returns the Instant.

    minusNanos()方法用于从此Instant减去给定的持续时间(以纳秒为单位),并返回Instant。

  • minusNanos() 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.

    minusNanos()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • minusNanos() method may throw an exception at the time of performing subtraction.

    minusNanos()方法在执行减法时可能会引发异常。

    ArithmeticException: This exception may throw when the calculated result value exceeds the limit.

    ArithmeticException :当计算结果值超过限制时,可能引发此异常。

Syntax:

句法:

    public Instant minusNanos(long nanos_val);

Parameter(s):

参数:

  • long nanos_val – represents the nanoseconds to be subtracted from this Instant.

    long nanos_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 nanoseconds from this Instant.

此方法的返回类型为Instant ,它返回的Instant保持从该Instant减去给定持续时间(以纳秒为单位)的值。

Example:

例:

// Java program to demonstrate the example 
// of minusNanos(long nanos_val) method 
// of Instant

import java.time.*;

public class MinusNanosOfInstant {
    public static void main(String args[]) {
        long nanos = 200000;

        // Instantiates two Instant
        Instant ins1 = Instant.parse("2006-04-03T05:10:15.60Z");
        Instant ins2 = Instant.now();

        // Display ins1,ins2 and nanos
        System.out.println("Instant ins1 and ins2: ");
        System.out.println("ins1: " + ins1);
        System.out.println("ins2: " + ins2);
        System.out.println("nanos to substract: " + nanos);

        System.out.println();

        // Here, this method subtracts the given duration
        // in nanoseconds from this Instant ins1 
        // i.e. here we are substracting the given
        // 200000 nanos from this ins1 

        Instant minus_nanos = ins1.minusNanos(nanos);

        // Display minus_nanos
        System.out.println("ins1.minusNanos(nanos): " + minus_nanos);

        // Here, this method subtracts the given duration
        // in nanoseconds from this Instant ins2 
        // i.e. here we are substracting the given
        // 200000 nanos from this ins2 

        minus_nanos = ins2.minusNanos(nanos);

        // Display minus_nanos
        System.out.println("ins2.minusNanos(nanos): " + minus_nanos);
    }
}

Output

输出量

Instant ins1 and ins2: 
ins1: 2006-04-03T05:10:15.600Z
ins2: 2020-05-26T23:36:39.457119Z
nanos to substract: 200000

ins1.minusNanos(nanos): 2006-04-03T05:10:15.599800Z
ins2.minusNanos(nanos): 2020-05-26T23:36:39.456919Z


翻译自: https://www.includehelp.com/java/instant-minusnanos-method-with-example.aspx

java 根据类名示例化类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值