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

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

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

ZonedDateTime.minusYears介绍

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

This operates on the local time-line, LocalDateTime#minusYears(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 minusYears(long amount) {
  return dt.minusYears(amount);
}

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

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

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

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

代码示例来源:origin: org.xbib/ftp-client

ZonedDateTime zonedDateTime =  ZonedDateTime.parse(timestampStr, df);
if (zonedDateTime.isAfter(ZonedDateTime.now())) {
  zonedDateTime = zonedDateTime.minusYears(1L);
  zonedDateTime = zonedDateTime.minusYears(99L);

代码示例来源:origin: simplesteph/kafka-connect-github-source

public static ConfigDef conf() {
  return new ConfigDef()
      .define(TOPIC_CONFIG, Type.STRING, Importance.HIGH, TOPIC_DOC)
      .define(OWNER_CONFIG, Type.STRING, Importance.HIGH, OWNER_DOC)
      .define(REPO_CONFIG, Type.STRING, Importance.HIGH, REPO_DOC)
      .define(BATCH_SIZE_CONFIG, Type.INT, 100, new BatchSizeValidator(), Importance.LOW, BATCH_SIZE_DOC)
      .define(SINCE_CONFIG, Type.STRING, ZonedDateTime.now().minusYears(1).toInstant().toString(),
          new TimestampValidator(), Importance.HIGH, SINCE_DOC)
      .define(AUTH_USERNAME_CONFIG, Type.STRING, "", Importance.HIGH, AUTH_USERNAME_DOC)
      .define(AUTH_PASSWORD_CONFIG, Type.PASSWORD, "", Importance.HIGH, AUTH_PASSWORD_DOC);
}

代码示例来源:origin: OpenGamma/Strata

public void test_relativeTime() {
 SabrParametersSwaptionVolatilities prov = SabrParametersSwaptionVolatilities.of(NAME, CONV, DATE_TIME, PARAM);
 double test1 = prov.relativeTime(DATE_TIME);
 assertEquals(test1, 0d);
 double test2 = prov.relativeTime(DATE_TIME.plusYears(2));
 double test3 = prov.relativeTime(DATE_TIME.minusYears(2));
 assertEquals(test2, -test3, 1e-2);
}

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

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

代码示例来源:origin: OpenGamma/Strata

public void test_relativeTime() {
 SabrParametersIborCapletFloorletVolatilities prov =
   SabrParametersIborCapletFloorletVolatilities.of(NAME, EUR_EURIBOR_3M, DATE_TIME, PARAM);
 double test1 = prov.relativeTime(DATE_TIME);
 assertEquals(test1, 0d);
 double test2 = prov.relativeTime(DATE_TIME.plusYears(2));
 double test3 = prov.relativeTime(DATE_TIME.minusYears(2));
 assertEquals(test2, -test3, 1e-2);
}

代码示例来源:origin: com.cronutils/cron-utils

private ExecutionTimeResult getPreviousPotentialMonth(final ZonedDateTime date, final int highestDay, final int highestHour,
    final int highestMinute, final int highestSecond) {
  NearestValue nearestValue;
  ZonedDateTime newDate;
  nearestValue = months.getPreviousValue(date.getMonthValue(), 0);
  final int previousMonths = nearestValue.getValue();
  if (nearestValue.getShifts() > 0) {
    newDate = ZonedDateTime.of(
        LocalDate.of(date.getYear(), 12, 31),
        MAX_SECONDS,
        date.getZone()
    ).minusYears(nearestValue.getShifts());
    return new ExecutionTimeResult(newDate, false);
  }
  else {
    newDate = ZonedDateTime.of(date.getYear(), date.getMonthValue(), 1, 0, 0, 0, 0, date.getZone()).minusNanos(1);
    return new ExecutionTimeResult(newDate, false);
  }
}

代码示例来源:origin: org.xbib/ftp-client

zonedDateTime = zonedDateTime.minusYears(1L);

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

@Override
public ZonedDateTime dateAddDuration(ZonedDateTime date, Duration duration) {
  if (date == null || duration == null) {
    return null;
  }
  try {
    int years = duration.getYears();
    int months = duration.getMonths();
    int days = duration.getDays();
    if (duration.getSign() == -1) {
      return date
          .minusYears(years)
          .minusMonths(months)
          .minusDays(days);
    } else {
      return date
          .plusYears(years)
          .plusMonths(months)
          .plusDays(days);
    }
  } catch (Throwable e) {
    String message = String.format("dateAdd(%s, %s)", date, duration);
    logError(message, e);
    return null;
  }
}

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

@Override
public ZonedDateTime dateSubtractDuration(ZonedDateTime date, Duration duration) {
  if (date == null || duration == null) {
    return null;
  }
  try {
    int years = duration.getYears();
    int months = duration.getMonths();
    int days = duration.getDays();
    if (duration.getSign() == -1) {
      return date
          .plusYears(years)
          .plusMonths(months)
          .plusDays(days);
    } else {
      return date
          .minusYears(years)
          .minusMonths(months)
          .minusDays(days);
    }
  } catch (Throwable e) {
    String message = String.format("dateSubtract(%s, %s)", date, duration);
    logError(message, e);
    return null;
  }
}

代码示例来源:origin: goldmansachs/jdmn

@Override
public ZonedDateTime dateAddDuration(ZonedDateTime date, Duration duration) {
  if (date == null || duration == null) {
    return null;
  }
  try {
    int years = duration.getYears();
    int months = duration.getMonths();
    int days = duration.getDays();
    if (duration.getSign() == -1) {
      return date
          .minusYears(years)
          .minusMonths(months)
          .minusDays(days);
    } else {
      return date
          .plusYears(years)
          .plusMonths(months)
          .plusDays(days);
    }
  } catch (Throwable e) {
    String message = String.format("dateAdd(%s, %s)", date, duration);
    logError(message, e);
    return null;
  }
}

代码示例来源:origin: goldmansachs/jdmn

@Override
public ZonedDateTime dateSubtractDuration(ZonedDateTime date, Duration duration) {
  if (date == null || duration == null) {
    return null;
  }
  try {
    int years = duration.getYears();
    int months = duration.getMonths();
    int days = duration.getDays();
    if (duration.getSign() == -1) {
      return date
          .plusYears(years)
          .plusMonths(months)
          .plusDays(days);
    } else {
      return date
          .minusYears(years)
          .minusMonths(months)
          .minusDays(days);
    }
  } catch (Throwable e) {
    String message = String.format("dateSubtract(%s, %s)", date, duration);
    logError(message, e);
    return null;
  }
}

代码示例来源:origin: mesos/elasticsearch

@Test
public void canParseTask() throws Exception {
  final ZonedDateTime nowUTC = ZonedDateTime.now(ZoneOffset.UTC);
  when(clock.nowUTC()).thenReturn(nowUTC.minusYears(100));
  final Protos.TaskID taskId = Protos.TaskID.newBuilder().setValue("TaskID").build();
  final Protos.TaskInfo taskInfo = createTaskInfo(taskId, createData(Optional.of(nowUTC)));
  final Protos.TaskStatus taskStatus = Protos.TaskStatus.newBuilder()
      .setTaskId(taskId)
      .setState(Protos.TaskState.TASK_STAGING)
      .build();
  final Task task = TaskInfoFactory.parse(taskInfo, taskStatus, clock);
  assertEquals(nowUTC, task.getStartedAt());
  verify(clock, never()).nowUTC();
}

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

if (duration.getSign() == -1) {
  return dateTime
      .minusYears(years)
      .minusMonths(months)
      .minusDays(days)

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

} else {
  return dateTime
      .minusYears(years)
      .minusMonths(months)
      .minusDays(days)

代码示例来源:origin: goldmansachs/jdmn

if (duration.getSign() == -1) {
  return dateTime
      .minusYears(years)
      .minusMonths(months)
      .minusDays(days)

代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

);
ZonedDateTime past = reference.minusYears( 1 ).minusMonths( 1 ).minusHours( 1 );
dummy = new PastDummyEntity( past );

代码示例来源:origin: goldmansachs/jdmn

} else {
  return dateTime
      .minusYears(years)
      .minusMonths(months)
      .minusDays(days)

相关文章

ZonedDateTime类方法