java.time.OffsetDateTime.toLocalTime()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(117)

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

OffsetDateTime.toLocalTime介绍

[英]Gets the LocalTime part of this date-time.

This returns a LocalTime with the same hour, minute, second and nanosecond as this date-time.
[中]获取此日期时间的LocalTime部分。
这将返回与此日期时间相同的小时、分钟、秒和纳秒的本地时间。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
  public LocalTime convert(OffsetDateTime source) {
    return source.toLocalTime();
  }
}

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

@Override
  public LocalTime convert(OffsetDateTime source) {
    return source.toLocalTime();
  }
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
public LocalTime decode(final BsonReader reader, final DecoderContext decoderContext) {
  return Instant.ofEpochMilli(validateAndReadDateTime(reader)).atOffset(ZoneOffset.UTC).toLocalTime();
}

代码示例来源:origin: apache/servicemix-bundles

@Override
  public LocalTime convert(OffsetDateTime source) {
    return source.toLocalTime();
  }
}

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

OffsetDateTime odt = instant.atOffset( ZoneOffset.UTC );
LocalTime lt = odt.toLocalTime();  // 10:00:00

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

ZoneOffset offset = ZoneOffset.ofHours( -7 );
OffsetDateTime odt = OffsetDateTime.now( offset );
String output1 = odt.toLocalTime().toString();
System.out.println( "Current time in " + offset + ": " + output1 );

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

/**
 * Checks if the instant of this date-time is equal to that of the specified date-time.
 * <p>
 * This method differs from the comparison in {@link #compareTo} and {@link #equals}
 * in that it only compares the instant of the date-time. This is equivalent to using
 * {@code dateTime1.toInstant().equals(dateTime2.toInstant());}.
 *
 * @param other  the other date-time to compare to, not null
 * @return true if the instant equals the instant of the specified date-time
 */
public boolean isEqual(OffsetDateTime other) {
  return toEpochSecond() == other.toEpochSecond() &&
      toLocalTime().getNano() == other.toLocalTime().getNano();
}

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

/**
 * Checks if the instant of this date-time is before that of the specified date-time.
 * <p>
 * This method differs from the comparison in {@link #compareTo} in that it
 * only compares the instant of the date-time. This is equivalent to using
 * {@code dateTime1.toInstant().isBefore(dateTime2.toInstant());}.
 *
 * @param other  the other date-time to compare to, not null
 * @return true if this is before the instant of the specified date-time
 */
public boolean isBefore(OffsetDateTime other) {
  long thisEpochSec = toEpochSecond();
  long otherEpochSec = other.toEpochSecond();
  return thisEpochSec < otherEpochSec ||
    (thisEpochSec == otherEpochSec && toLocalTime().getNano() < other.toLocalTime().getNano());
}

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

/**
 * Checks if the instant of this date-time is after that of the specified date-time.
 * <p>
 * This method differs from the comparison in {@link #compareTo} and {@link #equals} in that it
 * only compares the instant of the date-time. This is equivalent to using
 * {@code dateTime1.toInstant().isAfter(dateTime2.toInstant());}.
 *
 * @param other  the other date-time to compare to, not null
 * @return true if this is after the instant of the specified date-time
 */
public boolean isAfter(OffsetDateTime other) {
  long thisEpochSec = toEpochSecond();
  long otherEpochSec = other.toEpochSecond();
  return thisEpochSec > otherEpochSec ||
    (thisEpochSec == otherEpochSec && toLocalTime().getNano() > other.toLocalTime().getNano());
}

代码示例来源:origin: epam/DLab

@Override
public void executeTerminateResourceJob(boolean isAppliedForClusters) {
  OffsetDateTime currentDateTime = OffsetDateTime.now();
  List<SchedulerJobData> jobsToTerminate =
      getSchedulerJobsForAction(UserInstanceStatus.TERMINATED, currentDateTime, isAppliedForClusters);
  if (!jobsToTerminate.isEmpty()) {
    log.debug(isAppliedForClusters ? "Scheduler computational resource terminate job is executing..." :
        "Scheduler exploratory terminate job is executing...");
    log.info(CURRENT_DATETIME_INFO, LocalTime.of(currentDateTime.toLocalTime().getHour(),
        currentDateTime.toLocalTime().getMinute()), currentDateTime.toLocalDate(),
        currentDateTime.getDayOfWeek());
    log.info(isAppliedForClusters ? "Quantity of clusters for terminating: {}" :
        "Quantity of exploratories for terminating: {}", jobsToTerminate.size());
    jobsToTerminate.forEach(job ->
        changeResourceStatusTo(UserInstanceStatus.TERMINATED, job, isAppliedForClusters));
  }
}

代码示例来源:origin: epam/DLab

@Override
public void executeStartResourceJob(boolean isAppliedForClusters) {
  OffsetDateTime currentDateTime = OffsetDateTime.now();
  List<SchedulerJobData> jobsToStart =
      getSchedulerJobsForAction(UserInstanceStatus.RUNNING, currentDateTime, isAppliedForClusters);
  if (!jobsToStart.isEmpty()) {
    log.debug(isAppliedForClusters ? "Scheduler computational resource start job is executing..." :
        "Scheduler exploratory start job is executing...");
    log.info(CURRENT_DATETIME_INFO, LocalTime.of(currentDateTime.toLocalTime().getHour(),
        currentDateTime.toLocalTime().getMinute()), currentDateTime.toLocalDate(),
        currentDateTime.getDayOfWeek());
    log.info(isAppliedForClusters ? "Quantity of clusters for starting: {}" :
        "Quantity of exploratories for starting: {}", jobsToStart.size());
    jobsToStart.forEach(job -> changeResourceStatusTo(UserInstanceStatus.RUNNING, job, isAppliedForClusters));
  }
}

代码示例来源:origin: epam/DLab

@Override
public void executeStopResourceJob(boolean isAppliedForClusters) {
  OffsetDateTime currentDateTime = OffsetDateTime.now();
  List<SchedulerJobData> jobsToStop =
      getSchedulerJobsForAction(STOPPED, currentDateTime, isAppliedForClusters);
  if (!jobsToStop.isEmpty()) {
    log.debug(isAppliedForClusters ? "Scheduler computational resource stop job is executing..." :
        "Scheduler exploratory stop job is executing...");
    log.info(CURRENT_DATETIME_INFO, LocalTime.of(currentDateTime.toLocalTime().getHour(),
        currentDateTime.toLocalTime().getMinute()), currentDateTime.toLocalDate(),
        currentDateTime.getDayOfWeek());
    log.info(isAppliedForClusters ? "Quantity of clusters for stopping: {}" :
        "Quantity of exploratories for stopping: {}", jobsToStop.size());
    jobsToStop.forEach(job -> changeResourceStatusTo(STOPPED, job, isAppliedForClusters));
  }
}

代码示例来源:origin: oracle/pgql-lang

protected static String printLiteral(OffsetDateTime val) {
  return "TIMESTAMP '" + val.toLocalDate() + " " + printTime(val.toLocalTime()) + val.getOffset() + "'";
 }
}

代码示例来源:origin: net.sf.ebus/core

/**
 * Serializes the {@code OffsetDateTime.toLocalDate},
 * {@code LocalDateTime.toLocalTime}, and
 * {@code LocalDateTime.getOffset} values to {@code buffer}.
 * @param o an {@code OffsetDateTime} instance.
 * @param buffer write to this buffer.
 * @throws BufferOverflowException
 * if {@code buffer} does not contain enough space to store
 * the date, time, and offset values.
 */
@Override
public void serialize(final Object o,
           final ByteBuffer buffer)
  throws BufferOverflowException
{
  if (o instanceof OffsetDateTime)
  {
    final OffsetDateTime odt = (OffsetDateTime) o;
    buffer.putLong((odt.toLocalDate()).toEpochDay())
       .putLong((odt.toLocalTime()).toNanoOfDay())
       .putInt((odt.getOffset()).getTotalSeconds());
  }
  return;
} // end of serialize(Object, ByteBuffer)

代码示例来源:origin: pl.touk.esp/esp-process

public void write(Kryo kryo, Output out, OffsetDateTime obj) {
  LocalDateSerializer.write(out, obj.toLocalDate());
  LocalTimeSerializer.write(out, obj.toLocalTime());
  ZoneOffsetSerializer.write(out, obj.getOffset());
}

代码示例来源:origin: com.esotericsoftware/kryo-shaded

public void write (Kryo kryo, Output out, OffsetDateTime obj) {
  LocalDateSerializer.write(out, obj.toLocalDate());
  LocalTimeSerializer.write(out, obj.toLocalTime());
  ZoneOffsetSerializer.write(out, obj.getOffset());
}

代码示例来源:origin: com.esotericsoftware/kryo

public void write (Kryo kryo, Output out, OffsetDateTime obj) {
  LocalDateSerializer.write(out, obj.toLocalDate());
  LocalTimeSerializer.write(out, obj.toLocalTime());
  ZoneOffsetSerializer.write(out, obj.getOffset());
}

代码示例来源:origin: kpavlov/fixio

@SuppressWarnings("unchecked")
  public static <F extends AbstractField<?>> F fromLongValue(DataType type, int tagNum, long value) {
    switch (type) {
      case STRING:
        return (F) new StringField(tagNum, Long.toString(value));
      case FLOAT:
      case PRICE:
      case PRICEOFFSET:
      case PERCENTAGE:
      case AMT:
      case QTY:
//                return (F) new FloatField(tagNum, new FixedPointNumber(value));
      case INT:
      case LENGTH:
      case SEQNUM:
      case NUMINGROUP:
        return (F) new IntField(tagNum, (int) value);
      case UTCTIMESTAMP:
        return (F) new UTCTimestampField(tagNum, Instant.ofEpochMilli(value).atOffset(ZoneOffset.UTC).toZonedDateTime());
      case UTCTIMEONLY:
        return (F) new UTCTimeOnlyField(tagNum, Instant.ofEpochMilli(value).atOffset(ZoneOffset.UTC).toLocalTime());
      case UTCDATEONLY:
        return (F) new UTCDateOnlyField(tagNum, Instant.ofEpochMilli(value).atOffset(ZoneOffset.UTC).toLocalDate());
      default:
        throw new IllegalArgumentException("Value " + value + " is not applicable for field: " + tagNum
            + '(' + type + ')');
    }
  }

代码示例来源:origin: epam/DLab

/**
 * Checks if scheduler's time data satisfies existing time parameters.
 *
 * @param dto           scheduler job data.
 * @param dateTime      existing time data.
 * @param desiredStatus target exploratory status which has influence for time/date checking ('running' status
 *                      requires for checking start time, 'stopped' - for end time, 'terminated' - for
 *                      'terminatedDateTime').
 * @return true/false.
 */
private boolean isSchedulerJobDtoSatisfyCondition(SchedulerJobDTO dto, OffsetDateTime dateTime,
                         UserInstanceStatus desiredStatus) {
  ZoneOffset zOffset = dto.getTimeZoneOffset();
  OffsetDateTime roundedDateTime = OffsetDateTime.of(
      dateTime.toLocalDate(),
      LocalTime.of(dateTime.toLocalTime().getHour(), dateTime.toLocalTime().getMinute()),
      dateTime.getOffset());
  LocalDateTime convertedDateTime = ZonedDateTime.ofInstant(roundedDateTime.toInstant(),
      ZoneId.ofOffset(TIMEZONE_PREFIX, zOffset)).toLocalDateTime();
  return desiredStatus == TERMINATED ?
      Objects.nonNull(dto.getTerminateDateTime()) &&
          convertedDateTime.toLocalDate().equals(dto.getTerminateDateTime().toLocalDate())
          && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus)) :
      !convertedDateTime.toLocalDate().isBefore(dto.getBeginDate())
          && isFinishDateMatchesCondition(dto, convertedDateTime)
          && getDaysRepeat(dto, desiredStatus).contains(convertedDateTime.toLocalDate().getDayOfWeek())
          && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus));
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testObjectToOffsetTime() throws Exception {
  ZoneId zoneId = ZoneId.systemDefault();
  OffsetTime offsetTime = OffsetTime.now(zoneId);
  testObjectToOffsetTime(null, null);
  testObjectToOffsetTime(offsetTime, offsetTime);
  testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()), offsetTime);
  testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).atZoneSimilarLocal(zoneId), offsetTime);
  testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).toLocalDateTime(), offsetTime);
  testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).toLocalTime(), offsetTime);
  testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).toInstant(), offsetTime);
  testObjectToOffsetTime(Date.from(offsetTime.atDate(LocalDate.now()).toInstant()), offsetTime.truncatedTo(ChronoUnit.MILLIS));
  try {
    testObjectToOffsetTime("a string", offsetTime);
    fail();
  } catch (IllegalArgumentException e) {
    // expected
  }
}

相关文章