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
相關用法
- Java LocalTime until()用法及代碼示例
- Java LocalTime from()用法及代碼示例
- Java LocalTime plus()用法及代碼示例
- Java LocalTime with()用法及代碼示例
- Java LocalTime get()用法及代碼示例
- Java LocalTime withMinute()用法及代碼示例
- Java LocalTime equals()用法及代碼示例
- Java LocalTime format()用法及代碼示例
- Java LocalTime compareTo()用法及代碼示例
- Java LocalTime withHour()用法及代碼示例
- Java LocalTime adjustInto()用法及代碼示例
- Java LocalTime minus()用法及代碼示例
- Java LocalTime toString()用法及代碼示例
- Java LocalTime ofSecondOfDay()用法及代碼示例
- Java LocalTime isAfter()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 LocalTime ofNanoOfDay() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。