java.time.LocalTime.isSupported()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中java.time.LocalTime.isSupported()方法的一些代码示例,展示了LocalTime.isSupported()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalTime.isSupported()方法的具体详情如下:
包路径:java.time.LocalTime
类名称:LocalTime
方法名:isSupported

LocalTime.isSupported介绍

[英]Checks if the specified field is supported.

This checks if this time can be queried for the specified field. If false, then calling the #range(TemporalField) and #get(TemporalField) methods will throw an exception.

If the field is a ChronoField then the query is implemented here. The supported fields are:

  • NANO_OF_SECOND
  • NANO_OF_DAY
  • MICRO_OF_SECOND
  • MICRO_OF_DAY
  • MILLI_OF_SECOND
  • MILLI_OF_DAY
  • SECOND_OF_MINUTE
  • SECOND_OF_DAY
  • MINUTE_OF_HOUR
  • MINUTE_OF_DAY
  • HOUR_OF_AMPM
  • CLOCK_HOUR_OF_AMPM
  • HOUR_OF_DAY
  • CLOCK_HOUR_OF_DAY
  • AMPM_OF_DAY
    All other ChronoField instances will return false.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.isSupportedBy(TemporalAccessor)passing this as the argument. Whether the field is supported is determined by the field.
[中]检查是否支持指定的字段。
这将检查是否可以查询指定字段的时间。如果为false,则调用#range(TemporalField)和#get(TemporalField)方法将抛出异常。
如果该字段是一个ChronoField,则在此处实现查询。支持的字段包括:
*毫微秒
*纳米日
*微秒
*每天的微
*毫秒
*百万天
*第二分钟
*第二天
*每分钟
*一天中的一分钟
*每小时
*时钟每小时每分钟
*每天的小时数
*每天的时钟
*一天之最
所有其他ChronoField实例将返回false。
如果字段不是ChronoField,则通过调用TemporalField获得此方法的结果。Isupportedby(临时Accessor)将此作为参数传递。是否支持该字段取决于该字段。

代码示例

代码示例来源:origin: com.github.seratch/java-time-backport

@Override
public boolean isSupported(TemporalField field) {
  if (field == null) {
    return false;
  }
  return fieldValues.containsKey(field) ||
      (date != null && date.isSupported(field)) ||
      (time != null && time.isSupported(field));
}

代码示例来源:origin: com.sap.cloud.s4hana.datamodel/odata-core

@Override
@Nonnull
public ConvertedObject<Calendar> toDomainNonNull( @Nonnull final LocalTime object )
{
  final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
  calendar.clear();
  calendar.set(Calendar.HOUR_OF_DAY, object.getHour());
  calendar.set(Calendar.MINUTE, object.getMinute());
  calendar.set(Calendar.SECOND, object.getSecond());
  if( object.isSupported(ChronoField.MILLI_OF_SECOND) ) {
    calendar.set(Calendar.MILLISECOND, object.get(ChronoField.MILLI_OF_SECOND));
  }
  return ConvertedObject.of(calendar);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@Override
public long getLong(TemporalField field) {
  Jdk8Methods.requireNonNull(field, "field");
  Long value = getFieldValue0(field);
  if (value == null) {
    if (date != null && date.isSupported(field)) {
      return date.getLong(field);
    }
    if (time != null && time.isSupported(field)) {
      return time.getLong(field);
    }
    throw new DateTimeException("Field not found: " + field);
  }
  return value;
}

相关文章