- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中java.time.ZonedDateTime.plusYears()
方法的一些代码示例,展示了ZonedDateTime.plusYears()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.plusYears()
方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:plusYears
[英]Returns a copy of this ZonedDateTime with the specified period in years added.
This operates on the local time-line, LocalDateTime#plusYears(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#加上本地日期时间(长)。然后将其转换回ZoneDateTime,使用分区ID获取偏移量。
当转换回ZoneDateTime时,如果本地日期时间重叠,那么如果可能,将保留偏移量,否则将使用较早的偏移量。如果存在间隙,本地日期时间将根据间隙的长度向前调整。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: org.elasticsearch/elasticsearch
public ZonedDateTime plusYears(long amount) {
return dt.plusYears(amount);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
dateTime = dateTime.withDayOfYear(1).with(LocalTime.MIN);
} else {
dateTime = dateTime.plusYears(sign * num);
dateTime = dateTime.plusYears(1);
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
public ZonedDateTime plusYears(long amount) {
return dt.plusYears(amount);
}
代码示例来源:origin: apache/servicemix-bundles
public ZonedDateTime plusYears(long amount) {
return dt.plusYears(amount);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code ZonedDateTime} with the specified period in years subtracted.
* <p>
* This operates on the local time-line,
* {@link LocalDateTime#minusYears(long) subtracting years} 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 years the years to subtract, may be negative
* @return a {@code ZonedDateTime} based on this date-time with the years subtracted, not null
* @throws DateTimeException if the result exceeds the supported date range
*/
public ZonedDateTime minusYears(long years) {
return (years == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-years));
}
代码示例来源:origin: io.micronaut/runtime
/**
* This will search for the next time within the next 4 years. If there is no
* time matching, an InvalidArgumentException will be thrown (it is very
* likely that the cron expression is invalid, like the February 30th).
*
* @param afterTime A date-time with a time-zone in the ISO-8601 calendar system
* @return The next time within next 4 years
*/
public ZonedDateTime nextTimeAfter(ZonedDateTime afterTime) {
return nextTimeAfter(afterTime, afterTime.plusYears(FOUR));
}
代码示例来源:origin: frode-carlsen/cron
public ZonedDateTime nextTimeAfter(ZonedDateTime afterTime, long durationInMillis) {
// will search for the next time within the next durationInMillis
// millisecond. Be aware that the duration is specified in millis,
// but in fact the limit is checked on a day-to-day basis.
return nextTimeAfter(afterTime, afterTime.plus(Duration.ofMillis(durationInMillis)));
}
代码示例来源:origin: no.ssb.vtl/java-vtl-ssb-api-connector
private List<String> getPeriods(ZonedDateTime validFrom, ZonedDateTime validTo) {
if (periodType != PeriodType.YEAR) {
throw new UnsupportedOperationException("Period type: " + periodType + " not supported");
}
List<String> periods = new ArrayList<>();
ZonedDateTime current = validFrom;
ZonedDateTime nextYear =
ZonedDateTime.ofInstant(TimeUtil.now(), ZoneId.of(KLASS_TIME_ZONE))
.plusYears(1).with(DECEMBER).with(lastDayOfMonth()).withHour(23);
while (current.isBefore(validTo) && current.isBefore(nextYear)) {
periods.add(String.valueOf(current.getYear()));
current = current.plusYears(1);
}
return periods;
}
代码示例来源: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: 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: com.cronutils/cron-utils
private ExecutionTimeResult getNextPotentialMonth(final ZonedDateTime date, final int lowestHour, final int lowestMinute, final int lowestSecond) {
NearestValue nearestValue;
nearestValue = months.getNextValue(date.getMonthValue(), 0);
final int nextMonths = nearestValue.getValue();
if (nearestValue.getShifts() > 0) {
return new ExecutionTimeResult(date.truncatedTo(DAYS).withMonth(1).withDayOfMonth(1).plusYears(nearestValue.getShifts()), false);
}
final Optional<TimeNode> optionalDays = generateDays(cronDefinition,
ZonedDateTime.of(LocalDateTime.of(date.getYear(), nextMonths, 1, 0, 0), date.getZone()));
if (optionalDays.isPresent()) {
final List<Integer> days = optionalDays.get().getValues();
return new ExecutionTimeResult(
date.truncatedTo(SECONDS).withMonth(nextMonths).withDayOfMonth(days.get(0))
.with(LocalTime.of(lowestHour, lowestMinute, lowestSecond)), false);
} else {
return new ExecutionTimeResult(toBeginOfNextMonth(date), false);
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void setValidFromAndUntil() {
withPersistentCartDiscount(client(), cartDiscount -> {
final ZonedDateTime validFrom =
ZonedDateTime.of(2018, 8, 8, 0, 0, 0, 0, ZoneId.systemDefault());
final ZonedDateTime validUntil = ZonedDateTime.now().plusYears(1);
final CartDiscount updatedDiscountCode =
client().executeBlocking(CartDiscountUpdateCommand.of(cartDiscount, SetValidFromAndUntil.of(validFrom, validUntil)));
assertThat(updatedDiscountCode.getValidFrom()).isEqualTo(validFrom);
assertThat(updatedDiscountCode.getValidUntil()).isEqualTo(validUntil);
});
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void setValidFromAndUntil() {
withPersistentDiscountCode(client(), discountCode -> {
final ZonedDateTime validFrom =
ZonedDateTime.of(2018, 8, 8, 0, 0, 0, 0, ZoneId.systemDefault());
final ZonedDateTime validUntil = ZonedDateTime.now().plusYears(1);
final DiscountCode updatedDiscountCode =
client().executeBlocking(DiscountCodeUpdateCommand.of(discountCode, SetValidFromAndUntil.of(validFrom, validUntil)));
assertThat(updatedDiscountCode.getValidFrom()).isEqualTo(validFrom);
assertThat(updatedDiscountCode.getValidUntil()).isEqualTo(validUntil);
});
}
代码示例来源: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: commercetools/commercetools-jvm-sdk
@Test
public void setValidFromAndUntil() throws Exception {
withUpdateableProductDiscount(client(), discount -> {
final ZonedDateTime start = ZonedDateTime.parse("2015-07-09T07:46:40.230Z");
final ZonedDateTime end = start.plusYears(100);
final ProductDiscount updatedDiscount = client().executeBlocking(ProductDiscountUpdateCommand.of(discount, SetValidFromAndUntil.of(start,end )));
assertThat(updatedDiscount.getValidFrom()).isEqualTo(start);
assertThat(updatedDiscount.getValidUntil()).isEqualTo(end);
return updatedDiscount;
});
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void changeValidFromUntil() throws Exception {
withUpdateableProductDiscount(client(), discount -> {
final ZonedDateTime start = ZonedDateTime.parse("2015-07-09T07:46:40.230Z");
final ZonedDateTime end = start.plusYears(100);
final ProductDiscount updatedDiscount = client().executeBlocking(ProductDiscountUpdateCommand.of(discount, asList(SetValidFrom.of(start),SetValidUntil.of(end))));
assertThat(updatedDiscount.getValidFrom()).isEqualTo(start);
assertThat(updatedDiscount.getValidUntil()).isEqualTo(end);
return updatedDiscount;
});
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void changeValidFromUntil() throws Exception {
withPersistentCartDiscount(client(), cartDiscount -> {
final ZonedDateTime start = ZonedDateTime.parse("2015-07-09T07:46:40.230Z");
final ZonedDateTime end = start.plusYears(100);
final CartDiscount updatedDiscount =
client().executeBlocking(CartDiscountUpdateCommand.of(cartDiscount, asList(SetValidFrom.of(start),SetValidUntil.of(end))));
assertThat(updatedDiscount.getValidFrom()).isEqualTo(start);
assertThat(updatedDiscount.getValidUntil()).isEqualTo(end);
});
}
代码示例来源:origin: UniversaBlockchain/universa
@Test
public void checkContractExpiresAtDistantFutureTime() throws Exception{
Contract futureContract = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
futureContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey");
futureContract.getDefinition().setExpiresAt(futureContract.getCreatedAt().plusYears(50));
futureContract.seal();
assertTrue(futureContract.check());
System.out.println("Contract is valid: " + futureContract.isOk());
}
代码示例来源:origin: UniversaBlockchain/universa
@Test
public void checkContractExpiresAtDistantFutureTime() throws Exception{
Contract futureContract = Contract.fromDslFile(ROOT_PATH + "simple_root_contract.yml");
futureContract.addSignerKeyFromFile(ROOT_PATH+"_xer0yfe2nn1xthc.private.unikey");
futureContract.getDefinition().setExpiresAt(futureContract.getCreatedAt().plusYears(50));
futureContract.seal();
assertTrue(futureContract.check());
System.out.println("Contract is valid: " + futureContract.isOk());
registerAndCheckApproved(futureContract);
}
代码示例来源:origin: UniversaBlockchain/universa
private Contract createNetConfigContract(List<NodeInfo> netConfig,PrivateKey issuerKey) throws IOException {
Contract contract = new Contract();
contract.setIssuerKeys(issuerKey.getPublicKey());
contract.registerRole(new RoleLink("creator", "issuer"));
ListRole listRole = new ListRole("owner");
for(NodeInfo ni: netConfig) {
SimpleRole role = new SimpleRole(ni.getName());
contract.registerRole(role);
role.addKeyRecord(new KeyRecord(ni.getPublicKey()));
listRole.addRole(role);
}
listRole.setQuorum(netConfig.size()-1);
contract.registerRole(listRole);
RoleLink ownerLink = new RoleLink("ownerlink","owner");
ChangeOwnerPermission changeOwnerPermission = new ChangeOwnerPermission(ownerLink);
HashMap<String,Object> fieldsMap = new HashMap<>();
fieldsMap.put("net_config",null);
Binder modifyDataParams = Binder.of("fields",fieldsMap);
ModifyDataPermission modifyDataPermission = new ModifyDataPermission(ownerLink,modifyDataParams);
contract.addPermission(changeOwnerPermission);
contract.addPermission(modifyDataPermission);
contract.setExpiresAt(ZonedDateTime.now().plusYears(40));
contract.getStateData().set("net_config",netConfig);
contract.addSignerKey(issuerKey);
contract.seal();
return contract;
}
我创建了两个 ZonedDateTime 对象,我认为它们应该相等: public static void main(String[] args) { ZoneId zid = ZoneId.
假设我有一个 ZonedDateTime: ZonedDateTime zonedDateTime = ZonedDateTime.of(LocalDateTime.now(), ZoneI
给定以下单元测试: @Test public void zonedDateTimeCorrectlyRestoresItself() { // construct a new instance
我正在尝试将 ZonedDateTime 与以下代码进行比较: val now = ZonedDateTime.now() val query = for { x Timestamp.from(
我最近迁移到 Java 8,希望能更轻松地处理本地和分区时间。 但是,在我看来,在解析简单日期时,我遇到了一个简单的问题。 public static ZonedDateTime convertirA
您好,我已经搜索过类似的问题,但没有成功。我正在调用一个 ws,它将一个 token 发回给我,当它是有效的示例时: { "token": ..., "notBefore":"Thu 21
我有一个 ZonedDateTime 对象,我想根据给定的区域设置对其进行格式化。 IE。在美国,我希望格式为“M-dd-yy”,但在英国则应为“dd-M-yy”。 在给定的语言环境下执行此操作的最佳
在比较 ZonedDateTimes 时,使用 和 == 并不总是与使用 .isBefore、.isAfter 和 isEqual 相同,如下面的 Kotlin 示例所示: import java.
我有以下功能 public String getDateAndTimeInUserFormat(String value, DateTimeFormat inputFormat) { retu
我的时间以毫秒为单位,我需要将其转换为 ZonedDateTime 对象。 我有以下代码 long m = System.currentTimeMillis(); LocalDateTime d =
我尝试将字符串转换为 ZonedDateTime。这是我的代码: String startTime = "Wed Mar 21 2018 08:00:00 GMT 0330 (IRST)"; Stri
在比较 ZonedDateTimes 时,使用 和 == 并不总是与使用 .isBefore、.isAfter 和 isEqual 相同,如下面的 Kotlin 示例所示: import java.
我正在尝试获取存储为 UTC 的日期时间并将其转换为给定时区的日期时间。据我所知,ZonedDateTime 是正确的(“美国/芝加哥”比 UTC 晚 5 小时),但 DateTimeFormatte
我需要将字符串 2020-04-15T23:00:00+0000 转换为 ZonedDateTime。我尝试了以下方法,但没有成功: DateTimeFormatter formatter = Dat
如何将已设置的 ZonedDateTime 时间更改为“java.time.LocalTime.MIN”或“java.time.LocalTime.MAX”? ZonedDateTime date =
我正在尝试将字符串转换为 ZonedDateTime。 我尝试过以下操作: SimpleDateFormat zonedDateTimeFormat = new SimpleDateFormat("y
我目前正在研究日期在英国夏令时间之内和之外时的 ZonedDateTime 行为。 英国夏令时间从 3 月 25 日开始,增加一小时 (+1)。 我创建了几个 ZonedDateTime 实例(UTC
ZonedDateTime zdt3 = ZonedDateTime.parse("1999-09-09 09:09:09.999", DateTimeFormatter.of
我有一个返回年、月、日和小时的 DTO。因此将值从 DTO 传递到 ZonedDateTime.of 方法。此处,时间显示为太平洋标准时间上午 10 点。因此,尝试将其转换为 UTC。 当传递月份为
String ip="2011-05-01T06:47:35.422-05:00"; ZonedDateTime mzt = ZonedDateTime.parse(ip).toInstant().a
我是一名优秀的程序员,十分优秀!