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


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


LocalTime类的ofNanoOfDay()方法用于从nanos-of-day值获取LocalTime实例。这将返回一个指定的纳秒级的LocalTime,从0到24 * 60 * 60 * 1,000,000,000 – 1作为参数传递。

用法:

public static LocalTime ofNanoOfDay(long nanoOfDay)

参数:此方法接受单个参数nanoOfDay,它是从0到24 * 60 * 60 * 1,000,000,000 – 1的纳秒。


返回值:此方法返回从作为参数传递的nanoOfDay创建的LocalTime实例。

异常:如果作为参数传递的nanoofDay值无效,则此方法将引发DateTimeException。

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

示例1:

// Java program to demonstrate 
// LocalTime.ofNanoOfDay() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a nano of day 
        long nanoofday = 14245000000000l; 
  
        // applying ofNanoOfDay() 
        LocalTime value 
            = LocalTime.ofNanoOfDay(nanoofday); 
  
        // print result 
        System.out.println("LocalTime: "
                           + value); 
    } 
}
输出:
LocalTime: 03:57:25

示例2:

// Java program to demonstrate 
// LocalTime.ofNanoOfDay() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a nano of day 
        long nanoofday = 5000000000l; 
  
        // applying ofNanoOfDay() 
        LocalTime value 
            = LocalTime.ofNanoOfDay(nanoofday); 
  
        // print result 
        System.out.println("LocalTime: "
                           + value); 
    } 
}
输出:
LocalTime: 00:00:05

参考文献:



相关用法


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