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



描述

java.time.ZonedDateTime.withNano(int nanoseconds) 方法返回此區域日期時間的副本,並更改納秒。

宣告

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

public ZonedDateTime withNano(int nanoseconds)

引數

nanoseconds − 在結果中設定納秒,介於 0 到 999,999,999 之間。

返回值

基於此日期且具有所請求納秒的區域日期時間,非空。

異常

DateTimeException − 如果小時值無效。

示例

以下示例顯示了 java.time.ZonedDateTime.withNano(int nanoseconds) 方法的使用。

package com.tutorialspoint;

import java.time.ZonedDateTime;

public class ZonedDateTimeDemo {
   public static void main(String[] args) {
      
      ZonedDateTime date = ZonedDateTime.parse("2017-03-28T12:25:38.492+05:30[Asia/Calcutta]");
      ZonedDateTime result = date.withNano(30000);
      System.out.println(result);  
   }
}

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

2017-03-28T12:25:38.000030+05:30[Asia/Calcutta]
廣告