Java中的LocalDateTime類的isSupported()方法檢查是否支持指定的單位或字段。
用法:
public boolean isSupported(TemporalUnit unit) or public boolean isSupported(TemporalField field)
參數:此方法接受一個參數字段,該字段指定要檢查的字段,null返回false;或者,它接受一個參數單元,指定要檢查的字段,null返回false。
返回值:如果此日期支持字段單位,則該函數返回true,否則返回false。
以下示例程序旨在說明LocalDateTime.isSupported()方法:
程序1:
// Program to illustrate the isSupported(TemporalUnit) method
import java.util.*;
import java.time.*;
import java.time.temporal.ChronoUnit;
public class GfG {
public static void main(String[] args)
{
// Parses the date
LocalDateTime dt1
= LocalDateTime.parse("2018-11-03T12:45:30");
// Prints the date
System.out.println(dt1);
System.out.println(dt1.isSupported(ChronoUnit.DAYS));
}
}
輸出:
2018-11-03T12:45:30 true
程序2:
// Program to illustrate the isSupported(TemporalField) method
import java.util.*;
import java.time.*;
import java.time.temporal.ChronoField;
public class GfG {
public static void main(String[] args)
{
// Parses the date
LocalDateTime dt1
= LocalDateTime.parse("2018-11-03T12:45:30");
// Prints the date
System.out.println(dt1);
System.out.println(
dt1
.isSupported(ChronoField.DAY_OF_WEEK));
}
}
輸出:
2018-11-03T12:45:30 true
參考:https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#isSupported(java.time.temporal.TemporalField)
相關用法
- Java Month isSupported()用法及代碼示例
- Java Instant isSupported()用法及代碼示例
- Java Charset isSupported()用法及代碼示例
- Java LocalTime isSupported()用法及代碼示例
- Java ZonedDateTime isSupported()用法及代碼示例
- Java MonthDay isSupported()用法及代碼示例
- Java LocalDate isSupported()用法及代碼示例
- Java Year isSupported(TemporalUnit)用法及代碼示例
- Java ChronoZonedDateTime isSupported(TemporalUnit)用法及代碼示例
- Java ZoneOffset isSupported(TemporalField)用法及代碼示例
- Java YearMonth isSupported(TemporalField)用法及代碼示例
- Java ChronoLocalDateTime isSupported(TemporalUnit)用法及代碼示例
- Java Year isSupported(TemporalField)用法及代碼示例
- Java ChronoZonedDateTime isSupported(TemporalField)用法及代碼示例
- Java YearMonth isSupported(TemporalUnit)用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 LocalDateTime isSupported() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。