org.threeten.bp.LocalTime.get()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(192)

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

LocalTime.get介绍

[英]Gets the value of the specified field from this time as an int.

This queries this time for the value for the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.

If the field is a ChronoField then the query is implemented here. The #isSupported(TemporalField) will return valid values based on this time, except NANO_OF_DAY and MICRO_OF_DAYwhich are too large to fit in an int and throw a DateTimeException. All other ChronoField instances will throw a DateTimeException.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom(TemporalAccessor)passing this as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.
[中]获取此时指定字段的int值。
这一次将查询指定字段的值。返回的值将始终在字段的有效值范围内。如果由于字段不受支持或其他原因而无法返回值,则会引发异常。
如果该字段是一个ChronoField,则在此处实现查询。#isSupported(TemporalField)将基于此时间返回有效值,但NANO_OF_DAY和MICRO_OF_DAY太大,无法放入int并引发DateTimeException。所有其他ChronoField实例将引发DateTimeException。
如果字段不是ChronoField,则通过调用TemporalField获得此方法的结果。getFrom(临时Accessor)将此作为参数传递。是否可以获得该值以及该值表示的内容由字段决定。

代码示例

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

@Override
public void serialize(LocalTime value, JsonGenerator g, SerializerProvider provider) throws IOException
{
  if (useTimestamp(provider)) {
    g.writeStartArray();
    g.writeNumber(value.getHour());
    g.writeNumber(value.getMinute());
    if(value.getSecond() > 0 || value.getNano() > 0)
    {
      g.writeNumber(value.getSecond());
      if(value.getNano() > 0)
      {
        if(provider.isEnabled(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS))
          g.writeNumber(value.getNano());
        else
          g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
      }
    }
    g.writeEndArray();
  } else {
    DateTimeFormatter dtf = _formatter;
    if (dtf == null) {
      dtf = _defaultFormatter();
    }
    g.writeString(value.format(dtf));
  }
}

代码示例来源:origin: ThreeTen/threetenbp

public int get(TemporalField field) {
  if (field instanceof ChronoField) {
    return (field.isTimeBased() ? time.get(field) : date.get(field));

代码示例来源:origin: ThreeTen/threetenbp

@Override
public int get(TemporalField field) {
  if (field instanceof ChronoField) {
    return (field.isTimeBased() ? time.get(field) : date.get(field));
  }
  return range(field).checkValidIntValue(getLong(field), field);
}

代码示例来源:origin: org.threeten/threetenbp

@Override
public int get(TemporalField field) {
  if (field instanceof ChronoField) {
    return (field.isTimeBased() ? time.get(field) : date.get(field));
  }
  return range(field).checkValidIntValue(getLong(field), field);
}

代码示例来源:origin: org.threeten/threetenbp

public int get(TemporalField field) {
  if (field instanceof ChronoField) {
    return (field.isTimeBased() ? time.get(field) : date.get(field));

相关文章