java.time.ZonedDateTime.plusWeeks()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(123)

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

ZonedDateTime.plusWeeks介绍

[英]Returns a copy of this ZonedDateTime with the specified period in weeks added.

This operates on the local time-line, LocalDateTime#plusWeeks(long) to the local date-time. This is then converted back to a ZonedDateTime, using the zone ID to obtain the offset.

When converting back to ZonedDateTime, if the local date-time is in an overlap, then the offset will be retained if possible, otherwise the earlier offset will be used. If in a gap, the local date-time will be adjusted forward by the length of the gap.

This instance is immutable and unaffected by this method call.
[中]返回此ZoneDateTime的副本,并添加指定的时间段(以周为单位)。
这在本地时间线上运行,LocalDateTime#加上本地日期时间(long)。然后将其转换回ZoneDateTime,使用分区ID获取偏移量。
当转换回ZoneDateTime时,如果本地日期时间重叠,那么如果可能,将保留偏移量,否则将使用较早的偏移量。如果存在间隙,本地日期时间将根据间隙的长度向前调整。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

public ZonedDateTime plusWeeks(long amount) {
  return dt.plusWeeks(amount);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

dateTime = dateTime.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).with(LocalTime.MIN);
} else {
  dateTime = dateTime.plusWeeks(sign * num);
  dateTime = dateTime.plusWeeks(1);

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

ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime now = ZonedDateTime.now( zoneId );
ZonedDateTime weekLater = now.plusWeeks( 1 );

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

ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime now = ZonedDateTime.now( zoneId );
ZonedDateTime later = now.plusWeeks( 1 );  // Generates a second object without modifying the first.

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

ZonedDateTime firstOfWeek = zdt.with ( ChronoField.DAY_OF_WEEK , 1 ); // ISO 8601, Monday is first day of week.
ZonedDateTime firstOfNextWeek = firstOfWeek.plusWeeks ( 1 );

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public ZonedDateTime plusWeeks(long amount) {
  return dt.plusWeeks(amount);
}

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

public ZonedDateTime plusWeeks(long amount) {
  return dt.plusWeeks(amount);
}

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

/**
 * Returns a copy of this {@code ZonedDateTime} with the specified period in weeks subtracted.
 * <p>
 * This operates on the local time-line,
 * {@link LocalDateTime#minusWeeks(long) subtracting weeks} to the local date-time.
 * This is then converted back to a {@code ZonedDateTime}, using the zone ID
 * to obtain the offset.
 * <p>
 * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap,
 * then the offset will be retained if possible, otherwise the earlier offset will be used.
 * If in a gap, the local date-time will be adjusted forward by the length of the gap.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param weeks  the weeks to subtract, may be negative
 * @return a {@code ZonedDateTime} based on this date-time with the weeks subtracted, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public ZonedDateTime minusWeeks(long weeks) {
  return (weeks == Long.MIN_VALUE ? plusWeeks(Long.MAX_VALUE).plusWeeks(1) : plusWeeks(-weeks));
}

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

ZonedDateTime firstOfWeek = zdt.with ( ChronoField.DAY_OF_WEEK , 1 ); // ISO 8601, Monday is first day of week.
firstOfWeek = firstOfWeek.toLocalDate ().atStartOfDay ( zoneId );
ZonedDateTime firstOfNextWeek = firstOfWeek.plusWeeks ( 1 );

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

ZonedDateTime zdt = firstSundayOfThisYear; // Var changing throughout loop.
List< ZonedDateTime > sundays = new ArrayList<>( 53 );  // Set initial capacity to maximum number of values.
while ( zdt.isBefore( zdtFirstOfNextYear ) ) {
  // Handle this iteration.
  sundays.add( zdt );
  System.out.println( "Sunday # " + sundays.size( ) + " : " + zdt );
  // Prepare next iteration.
  zdt = zdt.plusWeeks( 1 );
}

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

ZoneId z = ZoneId.of( "America/Montreal" );
ZonedDateTime now = ZonedDateTime.now( z );
ZonedDateTime start = now.minusWeeks( 1 );  // Simulating input.
ZonedDateTime stop = now.plusWeeks( 2 );  // Simulating input.

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

ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime yesterday = now.minusDays( 1 );
ZonedDateTime weekLater = now.plusWeeks( 1 );

代码示例来源:origin: vhoang55/springboot-jwt-angular2

public String createTokenForUser(UserDetails user) {
    final ZonedDateTime afterOneWeek = ZonedDateTime.now().plusWeeks(1);
    return Jwts.builder()
        .setSubject(user.getUsername())
        .signWith(SignatureAlgorithm.HS512, secret)
        .setExpiration(Date.from(afterOneWeek.toInstant()))
        .compact();
  }
}

代码示例来源:origin: CodeStory/fluent-http

@Override
public Payload body(Context context) {
 String uri = context.uri();
 URL url = webJarUrlFinder.url(uri);
 return new Payload(url)
  .withHeader(CACHE_CONTROL, "public, max-age=31536000")
  .withHeader(LAST_MODIFIED, RFC_1123_DATE_TIME.format(now().minusMonths(1L)))
  .withHeader(EXPIRES, RFC_1123_DATE_TIME.format(now().plusWeeks(1L)));
}

代码示例来源:origin: ybonnel/SimpleWeb4j

response.addHeader("last-modified", startTime.format(DateTimeFormatter.RFC_1123_DATE_TIME));
response.addHeader("expires",
    ZonedDateTime.now().plusWeeks(1).format(DateTimeFormatter.RFC_1123_DATE_TIME));

代码示例来源:origin: yahoo/sherlock

/**
 * Increment a zoned date time by a
 * certain amount of this granularity.
 *
 * @param date   the date to increment
 * @param amount amount to increment
 * @return a copy of the date incremented
 */
public ZonedDateTime increment(ZonedDateTime date, int amount) {
  switch (this) {
    case MINUTE:
      return date.plusMinutes(amount);
    case HOUR:
      return date.plusHours(amount);
    case DAY:
      return date.plusDays(amount);
    case WEEK:
      return date.plusWeeks(amount);
    case MONTH:
      return date.plusMonths(amount);
    default:
      return date.plusHours(amount);
  }
}

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

dateTime = dateTime.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).with(LocalTime.MIN);
} else {
  dateTime = dateTime.plusWeeks(sign * num);
  dateTime = dateTime.plusWeeks(1);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

dateTime = dateTime.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).with(LocalTime.MIN);
} else {
  dateTime = dateTime.plusWeeks(sign * num);
  dateTime = dateTime.plusWeeks(1);

相关文章

ZonedDateTime类方法