本文整理了Java中java.time.Period.plusDays()
方法的一些代码示例,展示了Period.plusDays()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Period.plusDays()
方法的具体详情如下:
包路径:java.time.Period
类名称:Period
方法名:plusDays
[英]Returns a copy of this period with the specified days added.
This adds the amount to the days unit in a copy of this period. The years and months units are unaffected. For example, "1 year, 6 months and 3 days" plus 2 days returns "1 year, 6 months and 5 days".
This instance is immutable and unaffected by this method call.
[中]返回添加了指定天数的此时段的副本。
这会将金额添加到此期间副本中的天数单位。年和月单位不受影响。例如,“1年、6个月和3天”加上2天返回“1年、6个月和5天”。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testLifecycle() {
doInJPA( this::entityManagerFactory, entityManager -> {
Event event = new Event( period );
entityManager.persist( event );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
Event event = entityManager.createQuery( "from Event", Event.class ).getSingleResult();
assertEquals( period, event.getSpan() );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
//tag::basic-jpa-convert-period-string-converter-immutability-plan-example[]
Event event = entityManager.createQuery( "from Event", Event.class ).getSingleResult();
event.setSpan(Period
.ofYears( 3 )
.plusMonths( 2 )
.plusDays( 1 )
);
//end::basic-jpa-convert-period-string-converter-immutability-plan-example[]
} );
}
代码示例来源:origin: org.codehaus.groovy/groovy-datetime
/**
* Returns a {@link java.time.Period} that is {@code days} days longer than this period.
* No normalization is performed.
*
* @param self a Period
* @param days the number of days to increase this Period by
* @return a Period
* @since 2.5.0
*/
public static Period plus(final Period self, long days) {
return self.plusDays(days);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this period with the specified days subtracted.
* <p>
* This subtracts the amount from the days unit in a copy of this period.
* The years and months units are unaffected.
* For example, "1 year, 6 months and 3 days" minus 2 days returns "1 year, 6 months and 1 day".
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param daysToSubtract the months to subtract, positive or negative
* @return a {@code Period} based on this period with the specified days subtracted, not null
* @throws ArithmeticException if numeric overflow occurs
*/
public Period minusDays(long daysToSubtract) {
return (daysToSubtract == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-daysToSubtract));
}
代码示例来源:origin: jtransc/jtransc
static public void main(String[] args) {
System.out.println("PeriodTest.main:");
System.out.println(Period.ofDays(0).toString());
System.out.println(Period.ofDays(1).toString());
System.out.println(Period.ofDays(1).plusDays(40).toString());
System.out.println(Period.parse(Period.ofDays(1).toString()));
}
}
代码示例来源:origin: net.time4j/time4j-core
break;
case WEEKS:
period = period.plusDays(Math.multiplyExact(amount, 7));
break;
case DAYS:
period = period.plusDays(amount);
break;
default:
内容来源于网络,如有侵权,请联系作者删除!