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

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

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

ZonedDateTime.minusWeeks介绍

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

This operates on the local time-line, LocalDateTime#minusWeeks(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的副本,并减去指定的周期(以周为单位)。
这在本地时间线上运行,本地日期时间#小于本地日期时间的周(长)。然后将其转换回ZoneDateTime,使用分区ID获取偏移量。
当转换回ZoneDateTime时,如果本地日期时间重叠,那么如果可能,将保留偏移量,否则将使用较早的偏移量。如果存在间隙,本地日期时间将根据间隙的长度向前调整。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

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

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

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

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

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

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

final ZonedDateTime input = ZonedDateTime.now();
System.out.println(input);
final ZonedDateTime startOfLastWeek = input.minusWeeks(1).with(DayOfWeek.MONDAY);
System.out.println(startOfLastWeek);
final ZonedDateTime endOfLastWeek = startOfLastWeek.plusDays(6);
System.out.println(endOfLastWeek);

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

final ZonedDateTime input = ZonedDateTime.now();

for(int i = 1; i < 10; i++) {
  final ZonedDateTime startOfLastWeek = input.minusWeeks(i).with(DayOfWeek.MONDAY);
  System.out.print(startOfLastWeek.format(DateTimeFormatter.ISO_LOCAL_DATE));
  final ZonedDateTime endOfLastWeek = startOfLastWeek.plusDays(6);
  System.out.println(" - " + endOfLastWeek.format(DateTimeFormatter.ISO_LOCAL_DATE));
}

代码示例来源: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: yahoo/sherlock

/**
 * Decrement a zoned date time by a certain
 * amount of this granularity.
 *
 * @param date   zoned date time to decrease
 * @param amount the number of times to decrease
 * @return copy of the zoned date time
 */
public ZonedDateTime decrement(ZonedDateTime date, int amount) {
  switch (this) {
    case MINUTE:
      return date.minusMinutes(amount);
    case HOUR:
      return date.minusHours(amount);
    case DAY:
      return date.minusDays(amount);
    case WEEK:
      return date.minusWeeks(amount);
    case MONTH:
      return date.minusMonths(amount);
    default:
      return date.minusHours(amount);
  }
}

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

/**
 * Subtract granularity intervals of this type
 * from a given date time.
 *
 * @param now       the time to subtract intervals from
 * @param intervals the number of intervals to subtract
 * @param granularityRange range of granularity to aggregate on
 * @return a copied ZonedDateTime with the intervals subtracted
 */
public ZonedDateTime subtractIntervals(ZonedDateTime now, int intervals, int granularityRange) {
  int n = intervals - (intervals % granularityRange);
  switch (this) {
    case MINUTE:
      return now.minusMinutes(n);
    case HOUR:
      return now.minusHours(n);
    case DAY:
      return now.minusDays(n);
    case WEEK:
      return now.minusWeeks(n);
    case MONTH:
      return now.minusMonths(n);
    default:
      return now.minusHours(n);
  }
}

代码示例来源:origin: apache/incubator-rya

@Test
public void testWeeks() throws DatatypeConfigurationException, ValueExprEvaluationException {
  DatatypeFactory dtf = DatatypeFactory.newInstance();
  ZonedDateTime zTime = testThisTimeDate;
  String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
  ZonedDateTime zTime1 = zTime.minusWeeks(1);
  String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
  ZonedDateTime zTime2 = zTime.minusWeeks(7);
  String time2 = zTime2.format(DateTimeFormatter.ISO_INSTANT);
  Literal now = VF.createLiteral(dtf.newXMLGregorianCalendar(time));
  Literal nowMinusOne = VF.createLiteral(dtf.newXMLGregorianCalendar(time1));
  Literal nowMinusSeven = VF.createLiteral(dtf.newXMLGregorianCalendar(time2));
  DateTimeWithinPeriod func = new DateTimeWithinPeriod();
  assertEquals(TRUE, func.evaluate(VF, now, now, VF.createLiteral(1), OWLTime.WEEKS_URI));
  assertEquals(FALSE, func.evaluate(VF, now, nowMinusOne, VF.createLiteral(1), OWLTime.WEEKS_URI));
  assertEquals(TRUE, func.evaluate(VF, now, nowMinusOne, VF.createLiteral(2), OWLTime.WEEKS_URI));
  assertEquals(FALSE, func.evaluate(VF, now, nowMinusSeven, VF.createLiteral(7), OWLTime.WEEKS_URI));
}

相关文章

ZonedDateTime类方法