java.time.LocalDateTime.withSecond()方法的使用及代码示例

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

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

LocalDateTime.withSecond介绍

[英]Returns a copy of this LocalDateTime with the second-of-minute value altered.

This instance is immutable and unaffected by this method call.
[中]返回此LocalDateTime的副本,其分钟秒值已更改。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: alibaba/jetcache

switch (unit) {
  case DAYS:
    t = t.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
    break;
  case HOURS:
      t = t.plusHours(1);
    t = t.withMinute(0).withSecond(0).withNano(0);
    break;
  case MINUTES:
      t = t.plusMinutes(1);
    t = t.withSecond(0).withNano(0);
    break;
  case SECONDS:

代码示例来源:origin: Netflix/Priam

@Test
  public void testRestoreStatus() throws Exception {
    InstanceState.RestoreStatus restoreStatus = new InstanceState.RestoreStatus();
    restoreStatus.setStartDateRange(LocalDateTime.now().minusDays(2).withSecond(0).withNano(0));
    restoreStatus.setEndDateRange(LocalDateTime.now().minusHours(3).withSecond(0).withNano(0));
    restoreStatus.setExecutionStartTime(LocalDateTime.now().withSecond(0).withNano(0));
    LOG.info(restoreStatus.toString());

    InstanceState.RestoreStatus restoreStatus1 =
        GsonJsonSerializer.getGson()
            .fromJson(restoreStatus.toString(), InstanceState.RestoreStatus.class);
    LOG.info(restoreStatus1.toString());

    Assert.assertEquals(
        restoreStatus.getExecutionStartTime(), restoreStatus1.getExecutionStartTime());
    Assert.assertEquals(restoreStatus.getStartDateRange(), restoreStatus1.getStartDateRange());
    Assert.assertEquals(restoreStatus.getEndDateRange(), restoreStatus1.getEndDateRange());
  }
}

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

/**
 * Returns a copy of this {@code OffsetDateTime} with the second-of-minute value altered.
 * <p>
 * The offset does not affect the calculation and will be the same in the result.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param second  the second-of-minute to set in the result, from 0 to 59
 * @return an {@code OffsetDateTime} based on this date-time with the requested second, not null
 * @throws DateTimeException if the second value is invalid
 */
public OffsetDateTime withSecond(int second) {
  return with(dateTime.withSecond(second), offset);
}

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

LocalDateTime dt = …
dt = dt.withSecond(0).withNano(0).plusMinutes((65-dt.getMinute())%5);

代码示例来源:origin: OpenNMS/opennms

private Instant minusOne(Instant date){
  LocalDateTime current = LocalDateTime.ofInstant(date, UTC)
      .minus(1L, unit).withMinute(0).withSecond(0);
  return current.atZone(UTC).toInstant();
}

代码示例来源:origin: br.com.jarch/jarch-util

public static Date toDateStartOfDay(Date data) {
  LocalDateTime localDataHora = LocalDateTime.ofInstant(data.toInstant(), ZoneId.systemDefault()).withHour(0).withMinute(0).withSecond(0);
  return Date.from(localDataHora.atZone(ZoneId.systemDefault()).toInstant());
}

代码示例来源:origin: br.com.jarch/jarch-utils

public static Date toDateStartOfDay(Date data) {
  LocalDateTime localDataHora = LocalDateTime.ofInstant(data.toInstant(), ZoneId.systemDefault()).withHour(0).withMinute(0).withSecond(0);
  return Date.from(localDataHora.atZone(ZoneId.systemDefault()).toInstant());
}

代码示例来源:origin: br.com.jarch/jarch-utils

public static Date toDateEndOfDay(Date data) {
  LocalDateTime localDataHora = LocalDateTime.ofInstant(data.toInstant(), ZoneId.systemDefault()).withHour(23).withMinute(59).withSecond(59);
  return Date.from(localDataHora.atZone(ZoneId.systemDefault()).toInstant());
}

代码示例来源:origin: br.com.jarch/jarch-util

public static Date toDateEndOfDay(Date data) {
  LocalDateTime localDataHora = LocalDateTime.ofInstant(data.toInstant(), ZoneId.systemDefault()).withHour(23).withMinute(59).withSecond(59);
  return Date.from(localDataHora.atZone(ZoneId.systemDefault()).toInstant());
}

代码示例来源:origin: OpenNMS/opennms

private Instant plusOne(Instant date){
  LocalDateTime current = LocalDateTime.ofInstant(date, UTC)
      .plus(1L, unit).withMinute(0).withSecond(0);
  return current.atZone(UTC).toInstant();
}

代码示例来源:origin: snicoll-demos/smart-meter

@GetMapping(path = "/zones/{zoneId}/updates", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ResponseBody
public Flux<PowerGridSample> streamUpdates(@PathVariable String zoneId) {
  Instant startup = LocalDateTime.now().withSecond(0).toInstant(ZoneOffset.UTC);
  return this.powerGridSampleRepository
      .findWithTailableCursorByZoneIdAndTimestampAfter(zoneId, startup);
}

代码示例来源:origin: org.opennms.features.flows/org.opennms.features.flows.elastic

private Instant minusOne(Instant date){
  LocalDateTime current = LocalDateTime.ofInstant(date, UTC)
      .minus(1L, unit).withMinute(0).withSecond(0);
  return current.atZone(UTC).toInstant();
}

代码示例来源:origin: org.opennms.features.flows/org.opennms.features.flows.elastic

private Instant plusOne(Instant date){
  LocalDateTime current = LocalDateTime.ofInstant(date, UTC)
      .plus(1L, unit).withMinute(0).withSecond(0);
  return current.atZone(UTC).toInstant();
}

代码示例来源:origin: com.intuit.wasabi/wasabi-repository-datastax

List<Date> getUserAssignmentPartitions(Date fromTime, Date toTime) {
  final LocalDateTime startTime = LocalDateTime.ofInstant(fromTime.toInstant(), ZoneId.systemDefault())
      .withMinute(0)
      .withSecond(0)
      .withNano(0);
  final LocalDateTime endTime = LocalDateTime.ofInstant(toTime.toInstant(), ZoneId.systemDefault())
      .withMinute(0)
      .withSecond(0)
      .withNano(0);
  final long hours = Duration.between(startTime, endTime).toHours();
  return LongStream
      .rangeClosed(0, hours)
      .mapToObj(startTime::plusHours)
      .map(t -> Date.from(t.atZone(ZoneId.systemDefault()).toInstant()))
      .collect(Collectors.toList());
}

代码示例来源:origin: qala-io/datagen

public static LocalDateTime startOfMinute() {
  return now().withSecond(0).truncatedTo(SECONDS);
}
public static LocalDateTime now() {

代码示例来源:origin: snicoll-demos/smart-meter

private Instant generateReportTimestamp() {
  LocalDateTime now = LocalDateTime.now();
  return now.withSecond((now.getSecond() / this.periodicity) * this.periodicity)
      .withNano(0)
      .toInstant(ZoneOffset.UTC);
}

代码示例来源:origin: rubenlagus/TelegramBotsExample

/**
 * Find out next daily execution
 *
 * @param targetHour Target hour
 * @param targetMin  Target minute
 * @param targetSec  Target second
 * @return time in second to wait
 */
private long computNextDilay(int targetHour, int targetMin, int targetSec) {
  final LocalDateTime localNow = LocalDateTime.now(Clock.systemUTC());
  LocalDateTime localNextTarget = localNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec);
  while (localNow.compareTo(localNextTarget.minusSeconds(1)) > 0) {
    localNextTarget = localNextTarget.plusDays(1);
  }
  final Duration duration = Duration.between(localNow, localNextTarget);
  return duration.getSeconds();
}

代码示例来源:origin: OpenNMS/opennms

private Instant adjustEndTime(Date date){
    LocalDateTime current = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()),
        UTC).withMinute(59).withSecond(59).withNano(999999999);
    if(this.strategy == IndexStrategy.YEARLY){
      current = current.withMonth(12);
    }
    if(this.strategy == IndexStrategy.MONTHLY
        || this.strategy == IndexStrategy.YEARLY){
      current = current.with(TemporalAdjusters.lastDayOfMonth());
    }
    if(this.strategy == IndexStrategy.DAILY
        || this.strategy == IndexStrategy.MONTHLY
        || this.strategy == IndexStrategy.YEARLY){
      current = current.withHour(23);
    }
    return current.atZone(UTC).toInstant();
  }
}

代码示例来源:origin: de.knightsoft-net/mt-bean-validators

@Override
 public final boolean isValid(final LocalDateTime pvalue,
   final ConstraintValidatorContext pcontext) {
  if (pvalue == null) {
   return true;
  }
  final LocalDateTime dateLimit = LocalDateTime.now().minusYears(minYears).withHour(0)
    .withMinute(0).withSecond(0).withNano(0);
  return !dateLimit.isBefore(pvalue.withHour(0).withMinute(0).withSecond(0).withNano(0));
 }
}

代码示例来源:origin: com.intrbiz.bergamot/bergamot-timerange

public LocalDateTime computeNextStartTime(Clock clock)
  {
    LocalDateTime now  = LocalDateTime.now(clock);
    LocalDateTime next = now.withNano(0).withHour(this.startHour).withMinute(this.startMinute).withSecond(this.startSecond);
    if (! next.isAfter(now)) next = next.plusDays(1);
    return next;
  }
}

相关文章

LocalDateTime类方法