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

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

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

LocalTime.getLong介绍

[英]Gets the value of the specified field from this time as a long.

This queries this time for the value for the specified 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. 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.
[中]获取指定字段的值,该值从此时间起为long。
这一次将查询指定字段的值。如果由于字段不受支持或其他原因而无法返回值,则会引发异常。
如果该字段是一个ChronoField,则在此处实现查询。#isSupported(临时字段)将基于此时间返回有效值。所有其他ChronoField实例将引发DateTimeException。
如果字段不是ChronoField,则通过调用TemporalField获得此方法的结果。getFrom(临时Accessor)将此作为参数传递。是否可以获得该值以及该值表示的内容由字段决定。

代码示例

代码示例来源:origin: jtablesaw/tablesaw

@Test
public void testToNanoOfDay() {
  int pTime = of(7,18, 32, 232);
  LocalTime time = asLocalTime(pTime);
  assertEquals(time.getLong(ChronoField.NANO_OF_DAY), toNanoOfDay(pTime));
}

代码示例来源:origin: benas/random-beans

@Override
public LocalTime getRandomValue() {
  long minSecondOfDay = min.getLong(ChronoField.SECOND_OF_DAY);
  long maxSecondOfDay = max.getLong(ChronoField.SECOND_OF_DAY);
  long randomSecondOfDay = (long) nextDouble(minSecondOfDay, maxSecondOfDay);
  return LocalTime.ofSecondOfDay(randomSecondOfDay);
}

代码示例来源:origin: org.springframework.data/spring-data-cassandra

@Override
  public Long convert(LocalTime source) {
    return source.getLong(ChronoField.MILLI_OF_DAY);
  }
}

代码示例来源:origin: stackoverflow.com

LocalTime arrivalTime = LocalTime.parse(eta, DateTimeFormatter.ISO_LOCAL_TIME);
LocalTime currentTime = LocalTime.now();
final long difference = arrivalTime.getLong(ChronoField.MILLI_OF_DAY) - currentTime.getLong(ChronoField.MILLI_OF_DAY);

代码示例来源:origin: reactiverse/reactive-pg-client

private static void binaryEncodeTIME(LocalTime value, ByteBuf buff) {
 buff.writeLong(value.getLong(ChronoField.MICRO_OF_DAY));
}

代码示例来源:origin: io.reactiverse/reactive-pg-client

private static void binaryEncodeTIME(LocalTime value, ByteBuf buff) {
 buff.writeLong(value.getLong(ChronoField.MICRO_OF_DAY));
}

代码示例来源:origin: io.github.benas/random-beans

@Override
public LocalTime getRandomValue() {
  long minSecondOfDay = min.getLong(ChronoField.SECOND_OF_DAY);
  long maxSecondOfDay = max.getLong(ChronoField.SECOND_OF_DAY);
  long randomSecondOfDay = (long) nextDouble(minSecondOfDay, maxSecondOfDay);
  return LocalTime.ofSecondOfDay(randomSecondOfDay);
}

代码示例来源:origin: reactiverse/reactive-pg-client

private static void binaryEncodeTIMETZ(OffsetTime value, ByteBuf buff) {
 buff.writeLong(value.toLocalTime().getLong(ChronoField.MICRO_OF_DAY));
 // zone offset in seconds (should we change it to UTC ?)
 buff.writeInt(-value.getOffset().getTotalSeconds());
}

代码示例来源:origin: io.reactiverse/reactive-pg-client

private static void binaryEncodeTIMETZ(OffsetTime value, ByteBuf buff) {
 buff.writeLong(value.toLocalTime().getLong(ChronoField.MICRO_OF_DAY));
 // zone offset in seconds (should we change it to UTC ?)
 buff.writeInt(-value.getOffset().getTotalSeconds());
}

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

@Override
public long getLong(TemporalField field) {
  if (field instanceof ChronoField) {
    return (field.isTimeBased() ? time.getLong(field) : date.getLong(field));
  }
  return field.getFrom(this);
}

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

return getOffset().getTotalSeconds();
return time.getLong(field);

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

/**
 * Gets the value of the specified field from this date-time as a {@code long}.
 * <p>
 * This queries this date-time for the value for the specified 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.
 * <p>
 * If the field is a {@link ChronoField} then the query is implemented here.
 * The {@link #isSupported(TemporalField) supported fields} will return valid
 * values based on this date-time.
 * All other {@code ChronoField} instances will throw a {@code DateTimeException}.
 * <p>
 * If the field is not a {@code ChronoField}, then the result of this method
 * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
 * passing {@code this} as the argument. Whether the value can be obtained,
 * and what the value represents, is determined by the field.
 *
 * @param field  the field to get, not null
 * @return the value for the field
 * @throws DateTimeException if a value for the field cannot be obtained
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public long getLong(TemporalField field) {
  if (field instanceof ChronoField) {
    return (field.isTimeBased() ? time.getLong(field) : date.getLong(field));
  }
  return field.getFrom(this);
}

代码示例来源: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;
}

代码示例来源:origin: net.stickycode.scheduled/sticky-scheduled

/**
 * The delay in seconds to wait before the initial execution to align the schedule as specified.
 * <b>An alignment of 0 means there is no delay</b>
 * e.g.
 * <ul>
 * <li>if the user configured a schedule as 'every hour at 15 minutes past'</li>
 * <li>and the service started at 10 minutes past</li>
 * <li>then the period would be 60 * 60 seconds</li>
 * <li>and the delay would be 5 * 60 seconds such that the first execution is 15 minutes past</li>
 * </ul>
 */
@Override
public long getInitialDelay() {
 if (alignment == 0)
  return 0;
 LocalTime time = LocalTime.now();
 switch (alignmentUnit) {
 case HOURS:
  return calculateDelay(time.getHour(), alignment, 24);
 case MINUTES:
  return calculateDelay(time.getMinute(), alignment, 60);
 case SECONDS:
  return calculateDelay(time.getSecond(), alignment, 60);
 case MILLISECONDS:
  return calculateDelay(time.getLong(ChronoField.MILLI_OF_SECOND), alignment, 1000);
 default:
  throw new AlignmentNotSupportedException(alignmentUnit);
 }
}

相关文章