Java 中的 LocalTime toNanoOfDay() 方法


可以使用 Java 中 LocalTime 類中的 toNanoOfDay() 方法獲取當天的納秒形式。此方法不需要引數,並且以納秒形式返回當天時間。

下面給出了一個演示此操作的程式 −

示例

 線上演示

import java.time.*;
public class Main {
   public static void main(String[] args) {
      LocalTime lt = LocalTime.parse("05:15:30");
      System.out.println("The LocalTime is: " + lt);
      System.out.println("The nanoseconds of the day are: " + lt.toNanoOfDay());
   }
}

輸出

The LocalTime is: 05:15:30
The nanoseconds of the day are: 18930000000000

現在讓我們瞭解上述程式。

首先顯示 LocalTime。然後使用 toNanoOfDay() 方法以納秒形式獲取當天的時間。演示此操作的程式碼片段如下 −

LocalTime lt = LocalTime.parse("05:15:30");
System.out.println("The LocalTime is: " + lt);
System.out.println("The nanoseconds of the day are: " + lt.toNanoOfDay());

更新於: 30-Jul-2019

50 次瀏覽

啟動你的 職業道路

完成課程並獲得證書

開始學習
廣告
© . All rights reserved.