java.time.LocalTime.withNano() 方法示例



描述

java.time.LocalTime.withNano(int nanoOfSecond) 方法返回更改納秒部分後的 LocalTime 副本。

宣告

以下是 java.time.LocalTime.withNano(int nanoOfSecond) 方法的宣告。

public LocalTime withNano(int nanoOfSecond)

引數

nanoOfSecond − 設定在結果中的納秒,從 0 到 999,999,999。

返回值

基於此日期且具有請求納秒部分的 LocalTime,非空。

異常

DateTimeException − 如果納秒部分值無效。

示例

以下示例展示了 java.time.LocalTime.withNano(int nanoOfSecond) 方法的使用。

package com.tutorialspoint;

import java.time.LocalTime;

public class LocalTimeDemo {
   public static void main(String[] args) {

      LocalTime time = LocalTime.parse("10:15:30");
      LocalTime result = time.withNano(30000);
      System.out.println(result);  
   }
}

讓我們編譯並執行以上程式,這將產生以下結果 −

10:15:30.000030
廣告
© . All rights reserved.