public ZonedDateTime plusWeeks(long amount) { return dt.plusWeeks(amount); }
ZoneId zoneId = ZoneId.of( "America/Montreal" ); ZonedDateTime now = ZonedDateTime.now( zoneId ); ZonedDateTime weekLater = now.plusWeeks( 1 );
ZoneId zoneId = ZoneId.of( "America/Montreal" ); ZonedDateTime now = ZonedDateTime.now( zoneId ); ZonedDateTime later = now.plusWeeks( 1 ); // Generates a second object without modifying the first.
ZonedDateTime firstOfWeek = zdt.with ( ChronoField.DAY_OF_WEEK , 1 ); // ISO 8601, Monday is first day of week. ZonedDateTime firstOfNextWeek = firstOfWeek.plusWeeks ( 1 );
public ZonedDateTime plusWeeks(long amount) { return dt.plusWeeks(amount); }
public ZonedDateTime plusWeeks(long amount) { return dt.plusWeeks(amount); }
/** * 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)); }
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 );
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 ); }
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.
ZonedDateTime now = ZonedDateTime.now(); ZonedDateTime yesterday = now.minusDays( 1 ); ZonedDateTime weekLater = now.plusWeeks( 1 );
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(); } }
@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))); }
response.addHeader("last-modified", startTime.format(DateTimeFormatter.RFC_1123_DATE_TIME)); response.addHeader("expires", ZonedDateTime.now().plusWeeks(1).format(DateTimeFormatter.RFC_1123_DATE_TIME));
/** * 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); } }