當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。