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

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

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

LocalDateTime.plusDays介绍

[英]Returns a copy of this LocalDateTime with the specified period in days added.

This method adds the specified amount to the days field incrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.

For example, 2008-12-31 plus one day would result in 2009-01-01.

This instance is immutable and unaffected by this method call.
[中]返回此LocalDateTime的副本,并添加指定的期间(以天为单位)。
此方法将指定的金额添加到“天”字段中,并根据需要增加“月”和“年”字段,以确保结果仍然有效。仅当超过最大/最小年份时,结果才无效。
例如,2008-12-31加上一天将导致2009-01-01。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

LocalTime midnight = LocalTime.MIDNIGHT;
LocalDate today = LocalDate.now(ZoneId.of("Europe/Berlin"));
LocalDateTime todayMidnight = LocalDateTime.of(today, midnight);
LocalDateTime tomorrowMidnight = todayMidnight.plusDays(1);

代码示例来源:origin: yu199195/Raincat

/**
 * 计算 day 天后的时间.
 *
 * @param date 长日期
 * @param day  增加的天数
 * @return 增加后的日期
 */
public static LocalDateTime addDay(final LocalDateTime date, final int day) {
  return date.plusDays(day);
}

代码示例来源:origin: lets-blade/blade

/**
 * Sets the Date and Cache headers for the HTTP Response
 *
 * @param response    HTTP response
 * @param fileToCache file to extract content type
 */
private void setDateAndCacheHeaders(HttpResponse response, File fileToCache) {
  response.headers().set(HttpConst.DATE, DateKit.gmtDate());
  // Add cache headers
  if (httpCacheSeconds > 0) {
    response.headers().set(HttpConst.EXPIRES, DateKit.gmtDate(LocalDateTime.now().plusSeconds(httpCacheSeconds)));
    response.headers().set(HttpConst.CACHE_CONTROL, "private, max-age=" + httpCacheSeconds);
    if (null != fileToCache) {
      response.headers().set(HttpConst.LAST_MODIFIED, DateKit.gmtDate(new Date(fileToCache.lastModified())));
    } else {
      response.headers().set(HttpConst.LAST_MODIFIED, DateKit.gmtDate(LocalDateTime.now().plusDays(-1)));
    }
  }
}

代码示例来源:origin: lets-blade/blade

/**
 * Sets the Date and Cache headers for the HTTP Response
 *
 * @param response    HTTP response
 * @param fileToCache file to extract content type
 */
private void setDateAndCacheHeaders(HttpResponse response, File fileToCache) {
  response.headers().set(HttpConst.DATE, DateKit.gmtDate());
  // Add cache headers
  if (httpCacheSeconds > 0) {
    response.headers().set(HttpConst.EXPIRES, DateKit.gmtDate(LocalDateTime.now().plusSeconds(httpCacheSeconds)));
    response.headers().set(HttpConst.CACHE_CONTROL, "private, max-age=" + httpCacheSeconds);
    if (null != fileToCache) {
      response.headers().set(HttpConst.LAST_MODIFIED, DateKit.gmtDate(new Date(fileToCache.lastModified())));
    } else {
      response.headers().set(HttpConst.LAST_MODIFIED, DateKit.gmtDate(LocalDateTime.now().plusDays(-1)));
    }
  }
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Gets the time gap between now and next backup time.
 *
 * @return the time gap to next backup
 */
private long getTimeToNextBackup() {
 LocalDateTime now = LocalDateTime.now(Clock.systemUTC());
 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:mm");
 LocalTime backupTime = LocalTime.parse(ServerConfiguration
   .get(PropertyKey.MASTER_DAILY_BACKUP_TIME), formatter);
 LocalDateTime nextBackupTime = now.withHour(backupTime.getHour())
   .withMinute(backupTime.getMinute());
 if (nextBackupTime.isBefore(now)) {
  nextBackupTime = nextBackupTime.plusDays(1);
 }
 return ChronoUnit.MILLIS.between(now, nextBackupTime);
}

代码示例来源:origin: linlinjava/litemall

public static UserToken generateToken(Integer id) {
    UserToken userToken = null;

//        userToken = idMap.get(id);
//        if(userToken != null) {
//            tokenMap.remove(userToken.getToken());
//            idMap.remove(id);
//        }

    String token = CharUtil.getRandomString(32);
    while (tokenMap.containsKey(token)) {
      token = CharUtil.getRandomString(32);
    }

    LocalDateTime update = LocalDateTime.now();
    LocalDateTime expire = update.plusDays(1);

    userToken = new UserToken();
    userToken.setToken(token);
    userToken.setUpdateTime(update);
    userToken.setExpireTime(expire);
    userToken.setUserId(id);
    tokenMap.put(token, userToken);
    idMap.put(id, userToken);

    return userToken;
  }

代码示例来源:origin: linlinjava/litemall

LocalDateTime ship = order.getShipTime();
LocalDateTime now = LocalDateTime.now();
LocalDateTime expired = ship.plusDays(7);
if (expired.isAfter(now)) {
  continue;

代码示例来源:origin: linlinjava/litemall

/**
   * 可评价订单商品超期
   * <p>
   * 定时检查订单商品评价情况,如果确认商品超时七天则取消可评价状态
   * 定时时间是每天凌晨4点。
   */
  @Scheduled(cron = "0 0 4 * * ?")
  public void checkOrderComment() {
    logger.info("系统开启任务检查订单是否已经超期未评价");

    LocalDateTime now = LocalDateTime.now();
    List<LitemallOrder> orderList = orderService.queryComment();
    for (LitemallOrder order : orderList) {
      LocalDateTime confirm = order.getConfirmTime();
      LocalDateTime expired = confirm.plusDays(7);
      if (expired.isAfter(now)) {
        continue;
      }

      order.setComments((short) 0);
      orderService.updateWithOptimisticLocker(order);

      List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
      for (LitemallOrderGoods orderGoods : orderGoodsList) {
        orderGoods.setComment(-1);
        orderGoodsService.updateById(orderGoods);
      }
    }
  }
}

代码示例来源:origin: linlinjava/litemall

@GetMapping("create")
  public Object create(@LoginUser Integer userId, @NotNull String formId) {
    if (userId == null) {
      return ResponseUtil.unlogin();
    }

    LitemallUser user = userService.findById(userId);
    LitemallUserFormid userFormid = new LitemallUserFormid();
    userFormid.setOpenid(user.getWeixinOpenid());
    userFormid.setFormid(formId);
    userFormid.setIsprepay(false);
    userFormid.setUseamount(1);
    userFormid.setExpireTime(LocalDateTime.now().plusDays(7));
    formIdService.addUserFormid(userFormid);

    return ResponseUtil.ok();
  }
}

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

tempDateTime = tempDateTime.plusDays( days );

代码示例来源:origin: lets-blade/blade

@Test
public void testPrettyTime() {
  Assert.assertEquals("去年", DateKit.prettyTime(LocalDateTime.now().plusYears(-1), Locale.CHINESE));
  Assert.assertEquals("上个月", DateKit.prettyTime(LocalDateTime.now().plusMonths(-1), Locale.CHINESE));
  Assert.assertEquals("上周", DateKit.prettyTime(LocalDateTime.now().plusWeeks(-1), Locale.CHINESE));
  Assert.assertEquals("昨天", DateKit.prettyTime(LocalDateTime.now().plusDays(-1), Locale.CHINESE));
  Assert.assertEquals("1小时前", DateKit.prettyTime(LocalDateTime.now().plusHours(-1), Locale.CHINESE));
  Assert.assertEquals("1分钟前", DateKit.prettyTime(LocalDateTime.now().plusMinutes(-1), Locale.CHINESE));
  Assert.assertEquals("刚刚", DateKit.prettyTime(LocalDateTime.now().plusSeconds(-1), Locale.CHINESE));
  Assert.assertEquals("10秒前", DateKit.prettyTime(LocalDateTime.now().plusSeconds(-10), Locale.CHINESE));
}

代码示例来源:origin: linlinjava/litemall

LocalDateTime expired = couponUser.getAddTime().plusDays(days);
if (now.isAfter(expired)) {
  return null;

代码示例来源:origin: linlinjava/litemall

userFormid.setIsprepay(true);
userFormid.setUseamount(3);
userFormid.setExpireTime(LocalDateTime.now().plusDays(7));
formIdService.addUserFormid(userFormid);

代码示例来源:origin: linlinjava/litemall

LocalDateTime now = LocalDateTime.now();
couponUser.setStartTime(now);
couponUser.setEndTime(now.plusDays(coupon.getDays()));

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

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

代码示例来源:origin: linlinjava/litemall

LocalDateTime now = LocalDateTime.now();
couponUser.setStartTime(now);
couponUser.setEndTime(now.plusDays(coupon.getDays()));

代码示例来源:origin: linlinjava/litemall

LocalDateTime now = LocalDateTime.now();
couponUser.setStartTime(now);
couponUser.setEndTime(now.plusDays(coupon.getDays()));

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

@Test
public void testTimeWindow() {
  LocalDateTime dateTime = LocalDateTime.of(2018, 4, 10, 7, 30);
  startCol.append(dateTime);
  for (int i = 0; i < 49; i++) {
    dateTime = dateTime.plusDays(1);
    startCol.append(dateTime);
  }
  LongColumn timeWindows = startCol.timeWindow(ChronoUnit.DAYS, 5);
  assertEquals(0, timeWindows.get(0), 0.0001);
  assertEquals(9, timeWindows.max(), 0.0001);
  timeWindows = startCol.timeWindow(ChronoUnit.WEEKS, 1);
  assertEquals(0, timeWindows.get(0), 0.0001);
  assertEquals(7, timeWindows.max(), 0.0001);
  timeWindows = startCol.timeWindow(ChronoUnit.MONTHS, 1);
  assertEquals(0, timeWindows.get(0), 0.0001);
  assertEquals(1, timeWindows.max(), 0.0001);
  timeWindows = startCol.timeWindow(ChronoUnit.YEARS, 1);
  assertEquals(0, timeWindows.get(0), 0.0001);
  assertEquals(0, timeWindows.max(), 0.0001);
}

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

end.get(row.getRowNumber()).plusDays(1);
end.get(row.getRowNumber()).plusDays(1);

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

LocalDateTime afterDate = dateTime.plusDays(1);

相关文章

LocalDateTime类方法