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



說明

java.time.ZonedDateTime.isSupported(TemporalUnit unit) 方法檢查指定單位是否受支援。

宣告

以下是 java.time.ZonedDateTime.isSupported(TemporalUnit unit) 方法的宣告。

public boolean isSupported(TemporalUnit unit)

引數

unit - 要檢查的單位,如果為 null,則返回 false。

返回值

如果在此日期支援該單位,則返回 true;如果不支援,則返回 false。

示例

以下示例顯示了 java.time.ZonedDateTime.isSupported(TemporalUnit unit) 方法的使用情況。

package com.tutorialspoint;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

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

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

true
廣告
© . All rights reserved.