当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java LocalTime toNanoOfDay()用法及代码示例


LocalTime类的toNanoOfDay()方法用于从此LocalTime返回以天为单位的时间。此方法返回的值介于0到24 * 60 * 60 * 1,000,000,000 – 1之间。

用法:

public long toNanoOfDay()

参数:此方法不接受任何参数。


返回值:此方法返回一个long值,它是day值的毫微秒,并且等于此时间。

以下示例程序旨在说明toNanoOfDay()方法:

示例1:

// Java program to demonstrate 
// LocalTime.toNanoOfDay() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a LocalTime object 
        LocalTime time 
            = LocalTime.parse("19:34:50.63"); 
  
        // extract nano of day from toNanoOfDay() 
        long value = time.toNanoOfDay(); 
  
        // print result 
        System.out.println("Nano of day: "
                           + value); 
    } 
}
输出:
Nano of day: 70490630000000

示例2:

// Java program to demonstrate 
// LocalTime.toNanoOfDay() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a LocalTime object 
        LocalTime time 
            = LocalTime.parse("23:21:45.98"); 
  
        // extract nano of day from toNanoOfDay() 
        long value = time.toNanoOfDay(); 
  
        // print result 
        System.out.println("Nano of day: "
                           + value); 
    } 
}
输出:
Nano of day: 84105980000000

参考: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#toNanoOfDay()



相关用法


注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 LocalTime toNanoOfDay() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。