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



說明

java.time.OffsetTime.withNano(int nanoOfSecond) 方法返回一個 nanosecond 已經被改變的 OffsetTime 的副本。

宣告

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

public OffsetTime withNano(int nanoOfSecond)

java.time.OffsetTime withNano(int nanoOfSecond)

引數

nanoOfSecond − nanosecond 的值設在結果中,0 到 999,999,999 之間。

返回值

基於這個日期,具有指定的 nanosecond 的 OffsetTime,不可為 null。

異常

DateTimeException − 如果 nanosecond 的值無效。

示例

package com.tutorialspoint;

import java.time.OffsetTime;

public class OffsetTimeDemo {
   public static void main(String[] args) {
      
      OffsetTime time = OffsetTime.parse("10:15:30+01:00");
      OffsetTime result = time.withNano(30000);
      System.out.println(result);  
   }
}

現場演示

10:15:30.000030+01:00
列印頁面
廣告
© . All rights reserved.