本文整理了Java中org.joda.time.LocalDate.plusYears()
方法的一些代码示例,展示了LocalDate.plusYears()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.plusYears()
方法的具体详情如下:
包路径:org.joda.time.LocalDate
类名称:LocalDate
方法名:plusYears
[英]Returns a copy of this date plus the specified number of years.
This adds the specified number of years to the date. If adding years makes the day-of-month invalid, it is adjusted to the last valid day in the month. This LocalDate instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDate added = dt.plusYears(6);
LocalDate added = dt.plus(Period.years(6));
LocalDate added = dt.withFieldAdded(DurationFieldType.years(), 6);
[中]
代码示例来源:origin: killbill/killbill
@Override
public LocalDate addToLocalDate(final LocalDate localDate) {
if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
return localDate;
}
switch (unit) {
case DAYS:
return localDate.plusDays(number);
case WEEKS:
return localDate.plusWeeks(number);
case MONTHS:
return localDate.plusMonths(number);
case YEARS:
return localDate.plusYears(number);
case UNLIMITED:
default:
throw new IllegalStateException("Unexpected duration unit " + unit);
}
}
代码示例来源:origin: killbill/killbill
@Override
public LocalDate addToLocalDate(final LocalDate localDate) throws CatalogApiException {
if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
return localDate;
}
switch (unit) {
case DAYS:
return localDate.plusDays(number);
case WEEKS:
return localDate.plusWeeks(number);
case MONTHS:
return localDate.plusMonths(number);
case YEARS:
return localDate.plusYears(number);
case UNLIMITED:
default:
throw new CatalogApiException(ErrorCode.CAT_UNDEFINED_DURATION, unit);
}
}
代码示例来源:origin: dlew/joda-time-android
@Test
public void testGetRelativeTimeSpanStringWithPreposition() {
Context ctx = InstrumentationRegistry.getContext();
LocalDate today = LocalDate.now();
LocalDate tomorrow = today.plusDays(1);
LocalDate nextYear = today.plusYears(1);
assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, today, false));
assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, today, true));
assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, false));
assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, true));
assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, false));
assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, true));
DateTime todayDt = DateTime.now();
DateTime tomorrowDt = todayDt.plusDays(1);
DateTime nextYearDt = todayDt.plusYears(1);
assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, false));
assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, true));
assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, false));
assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, true));
assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, false));
assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, true));
}
代码示例来源:origin: org.schoellerfamily.gedbrowser/gedbrowser-analytics
/**
* Increment the date by a number of years.
*
* @param date the input date
* @param years the number of years
* @return new date
*/
protected final LocalDate plusYears(final LocalDate date, final int years) {
return date.plusYears(years);
}
代码示例来源:origin: nl.cloudfarming.client/calendar-api
public static LocalDate nextYear(LocalDate actual) {
return actual.plusYears(1);
}
代码示例来源:origin: com.github.fosin/cdp-utils
/**
* get$dateOfNextYear
*
* @return a {@link java.util.Date} object.
*/
public Date get$dateOfNextYear(){
LocalDate dt = new LocalDate();
return dt.plusYears(1).toDate();
}
代码示例来源:origin: com.github.fosin/cdp-utils
/**
* getNextYear
*
* @return a int.
*/
public int getNextYear(){
LocalDate dt = new LocalDate();
return dt.plusYears(1).getYear();
}
代码示例来源:origin: com.github.fosin/cdp-utils
/**
* getDateOfNextYear
*
* @return a {@link java.lang.String} object.
*/
public String getDateOfNextYear(){
LocalDate dt = new LocalDate();
return dt.plusYears(1).toString("yyyy-MM-dd");
}
代码示例来源:origin: org.integratedmodelling/klab-common
public static int daysInYear(int year) {
LocalDate ld = new LocalDate(year, 1, 1);
return Days.daysBetween(ld, ld.plusYears(1)).getDays();
}
代码示例来源:origin: com.atlassian.jira/jira-api
public LocalDate plusYears(int years)
{
return new LocalDate(toJodaLocalDate().plusYears(years));
}
代码示例来源:origin: rominirani/GradleWebAppSample
public int daysToNewYear() {
LocalDate fromDate = new LocalDate();
LocalDate newYear = fromDate.plusYears(1).withDayOfYear(1);
return Days.daysBetween(fromDate, newYear).getDays();
}
代码示例来源:origin: org.kill-bill.billing/killbill-overdue
@Override
public LocalDate addToLocalDate(final LocalDate localDate) {
if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
return localDate;
}
switch (unit) {
case DAYS:
return localDate.plusDays(number);
case WEEKS:
return localDate.plusWeeks(number);
case MONTHS:
return localDate.plusMonths(number);
case YEARS:
return localDate.plusYears(number);
case UNLIMITED:
default:
throw new IllegalStateException("Unexpected duration unit " + unit);
}
}
代码示例来源:origin: org.schoellerfamily.gedbrowser/gedbrowser-analytics
/**
* Adjust by the gap between children and to beginning of month.
*
* @param date the input date
* @return the adjusted date
*/
private LocalDate childAdjustment(final LocalDate date) {
if (date == null) {
return date;
}
return date.plusYears(typicals.gapBetweenChildren())
.withMonthOfYear(1).withDayOfMonth(1);
}
}
代码示例来源:origin: fluxtream/fluxtream-app
public void incrementTimespan() {
switch (timeUnit) {
case DAY:
fromDate = fromDate.plusDays(1);
break;
case WEEK:
fromDate = fromDate.plusWeeks(1);
break;
case MONTH:
fromDate = fromDate.plusMonths(1);
break;
case YEAR:
fromDate = fromDate.plusYears(1);
break;
}
}
代码示例来源:origin: com.helger/ph-bootstrap3
public BootstrapDateTimePicker (@Nullable final String sName,
@Nullable final String sValue,
@Nonnull final Locale aDisplayLocale)
{
ValueEnforcer.notNull (aDisplayLocale, "DisplayLocale");
m_sContainerID = GlobalIDFactory.getNewStringID ();
m_aEdit = new HCEdit (new RequestField (sName, sValue)).setPlaceholder ("");
m_aDisplayLocale = aDisplayLocale;
m_eLanguage = EDateTimePickerLanguage.getFromLocaleOrNull (aDisplayLocale);
if (m_eLanguage == null && !"en".equals (aDisplayLocale.getLanguage ()))
s_aLogger.warn ("Unsupported EDateTimePickerLanguage provided: " + aDisplayLocale);
m_eWeekStart = EDateTimePickerDayOfWeek.getFromJavaValueOrNull (Calendar.getInstance (aDisplayLocale)
.getFirstDayOfWeek ());
// Use the calendar icon as default prefix
m_aPrefixes.add (EBootstrapIcon.CALENDAR.getAsNode ());
// Default to end date + 1 year
setEndDate (PDTFactory.getCurrentLocalDate ().plusYears (1));
}
代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl
private boolean validateEffectiveDate(LocalDate date) {
if(date != null) {
if(date.isAfter(LocalDate.now().plusYears(1))) {
GlobalVariables.getMessageMap().putError("document.newMaintainableObject.effectiveDate", "balanceTransfer.effectiveDate.error");
return false;
}
}
return true;
}
代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl
private boolean validateEffectiveDate(LocalDate date) {
//Limit on future dates?
if(date.isAfter(LocalDate.now().plusYears(1))) {
GlobalVariables.getMessageMap().putError("document.newMaintainableObject.effectiveDate", "leavePayout.effectiveDate.overOneYear");
return false;
}
return true;
}
代码示例来源:origin: org.flowable/flowable-dmn-engine
public static Date addDate(Object startDate, Object years, Object months, Object days) {
LocalDate currentDate = new LocalDate(startDate);
currentDate = currentDate.plusYears(intValue(years));
currentDate = currentDate.plusMonths(intValue(months));
currentDate = currentDate.plusDays(intValue(days));
return currentDate.toDate();
}
代码示例来源:origin: org.schoellerfamily.gedbrowser/gedbrowser-analytics
/**
* Apply a standard adjustment from an ancestor's marriage date to a
* person's birth date.
*
* @param date the ancestor's marriage date
* @return the adjusted date
*/
private LocalDate ancestorAdjustment(final LocalDate date) {
if (date == null) {
return null;
}
return date.plusYears(typicals.ageAtMarriage()
+ typicals.gapBetweenChildren())
.withMonthOfYear(1).withDayOfMonth(1);
}
代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl
public List<TimesheetDocumentHeader> getDocumentHeadersForYear(String principalId, String year) {
Criteria crit = new Criteria();
List<TimesheetDocumentHeader> lstDocumentHeaders = new ArrayList<TimesheetDocumentHeader>();
crit.addEqualTo("principalId", principalId);
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy");
LocalDate currentYear = formatter.parseLocalDate(year);
LocalDate nextYear = currentYear.plusYears(1);
crit.addGreaterOrEqualThan("beginDate", currentYear.toDate());
crit.addLessThan("beginDate", nextYear.toDate());
QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
if (c != null) {
lstDocumentHeaders.addAll(c);
}
return lstDocumentHeaders;
}
内容来源于网络,如有侵权,请联系作者删除!