本文整理了Java中org.joda.time.DateTime.minusYears()
方法的一些代码示例,展示了DateTime.minusYears()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.minusYears()
方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:minusYears
[英]Returns a copy of this datetime minus the specified number of years.
The calculation will do its best to only change the year field retaining the same month of year. However, in certain circumstances, it may be necessary to alter smaller fields. For example, 2008-02-29 minus one year cannot result in 2007-02-29, so the day of month is adjusted to 2007-02-28.
The following three lines are identical in effect:
DateTime subtracted = dt.minusYears(6);
DateTime subtracted = dt.minus(Period.years(6));
DateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);
This datetime instance is immutable and unaffected by this method call.
[中]返回此datetime减去指定年数的副本。
计算将尽最大努力只更改保留一年中同一月份的“年份”字段。但是,在某些情况下,可能需要更改较小的字段。例如,2008-02-29减去一年不能得到2007-02-29,因此将月日调整为2007-02-28。
以下三行实际上是相同的:
DateTime subtracted = dt.minusYears(6);
DateTime subtracted = dt.minus(Period.years(6));
DateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);
此datetime实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: apache/flume
fixed = date.minusYears(1);
代码示例来源:origin: apache/incubator-druid
@Test
public void testAppliesToAll()
{
DateTime now = DateTimes.of("2012-12-31T01:00:00");
PeriodDropRule rule = new PeriodDropRule(
new Period("P5000Y"),
false
);
Assert.assertTrue(
rule.appliesTo(
builder.interval(
new Interval(
now.minusDays(2),
now.minusDays(1)
)
).build(),
now
)
);
Assert.assertTrue(
rule.appliesTo(
builder.interval(new Interval(now.minusYears(100), now.minusDays(1)))
.build(),
now
)
);
}
代码示例来源:origin: killbill/killbill
public static DateTime addOrRemoveDuration(final DateTime input, final List<Duration> durations, final boolean add) {
DateTime result = input;
for (final Duration cur : durations) {
switch (cur.getUnit()) {
case DAYS:
result = add ? result.plusDays(cur.getNumber()) : result.minusDays(cur.getNumber());
break;
case MONTHS:
result = add ? result.plusMonths(cur.getNumber()) : result.minusMonths(cur.getNumber());
break;
case YEARS:
result = add ? result.plusYears(cur.getNumber()) : result.minusYears(cur.getNumber());
break;
case UNLIMITED:
default:
throw new RuntimeException("Trying to move to unlimited time period");
}
}
return result;
}
代码示例来源:origin: git-commit-id/maven-git-commit-id-plugin
public DatedRevTag(AnyObjectId id, String tagName) {
this(id, tagName, DateTime.now().minusYears(2000));
}
代码示例来源:origin: apache/incubator-druid
Assert.assertFalse(
rule.appliesTo(
builder.interval(new Interval(now.minusYears(1), now.minusDays(1)))
.build(),
now
代码示例来源:origin: apache/incubator-druid
@Test
public void testUnUsedLowRange() throws IOException
{
coordinator.announceHistoricalSegments(SEGMENTS);
unUseSegment();
Assert.assertEquals(
SEGMENTS,
ImmutableSet.copyOf(
coordinator.getUnusedSegmentsForInterval(
defaultSegment.getDataSource(),
defaultSegment.getInterval().withStart(defaultSegment.getInterval().getStart().minus(1))
)
)
);
Assert.assertEquals(
SEGMENTS,
ImmutableSet.copyOf(
coordinator.getUnusedSegmentsForInterval(
defaultSegment.getDataSource(),
defaultSegment.getInterval().withStart(defaultSegment.getInterval().getStart().minusYears(1))
)
)
);
}
代码示例来源:origin: git-commit-id/maven-git-commit-id-plugin
public DatedRevTag(RevTag tag) {
this(tag.getId(), tag.getTagName(), (tag.getTaggerIdent() != null) ? new DateTime(tag.getTaggerIdent().getWhen()) : DateTime.now().minusYears(1900));
}
代码示例来源:origin: com.github.fosin/cdp-utils
/**
* get$datetimeOfLastYear
*
* @return a {@link java.util.Date} object.
*/
public Date get$datetimeOfLastYear(){
DateTime dt = new DateTime();
return dt.minusYears(1).toDate();
}
代码示例来源:origin: com.github.fosin/cdp-utils
/**
* getDatetimeOfLastYear
*
* @return a {@link java.lang.String} object.
*/
public String getDatetimeOfLastYear(){
DateTime dt = new DateTime();
return dt.minusYears(1).toString("yyyy-MM-dd HH:mm:ss");
}
代码示例来源:origin: io.codearte.jfairy/jfairy
@Override
public void generateDateOfBirth() {
if (dateOfBirth != null) {
return;
}
DateTime maxDate = timeProvider.getCurrentDate().minusYears(age);
DateTime minDate = maxDate.minusYears(1).plusDays(1);
dateOfBirth = dateProducer.randomDateBetweenTwoDates(minDate, maxDate);
}
代码示例来源:origin: stackoverflow.com
DateTime now = new DateTime();
DateTime twoYearsAgo = now.minusYears(2);
DateTime fiveDaysFromNow = now.plusDays(5);
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.appendPattern("E yyyy.MM.dd 'at' hh:mm:ss a zzz")
.toFormatter();
System.out.println(formatter.print(twoYearsAgo));
System.out.println(formatter.print(fiveDaysFromNow));
代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core
/**
* Creates a new Period instance that matches all the instants between N years before the instantiation and the
* instantiation.
*
* @param numberOfYears number of years to substract from current date
* @return The corresponding period object
*/
public static Period createSinceYearsPeriod(int numberOfYears)
{
DateTime dt = new DateTime();
return createPeriod(dt.minusYears(numberOfYears).getMillis(), dt.getMillis());
}
代码示例来源:origin: org.modeshape/modeshape-graph
/**
* {@inheritDoc}
*
* @see org.modeshape.graph.property.DateTime#minusYears(int)
*/
public org.modeshape.graph.property.DateTime minusYears( int years ) {
return new JodaDateTime(this.instance.minusYears(years));
}
代码示例来源:origin: rackerlabs/blueflood
@Test
public void testDecrementUnits() {
testFormat("now-10s", nowDateTime().minusSeconds(10));
testFormat("now-15min", nowDateTime().minusMinutes(15));
testFormat("now-100h", nowDateTime().minusHours(100));
testFormat("now-2d", nowDateTime().minusDays(2));
testFormat("now-6mon", nowDateTime().minusMonths(6));
testFormat("now-5y", nowDateTime().minusYears(5));
testFormat("-6h", nowDateTime().minusHours(6));
}
代码示例来源:origin: io.codearte.jfairy/jfairy
private String generateVatNumberForSoleTrader() {
DateTime lowerAgeLimit = DateTime.now().minusYears(SOLE_TRADER_LOWER_AGE_LIMIT);
DateTime upperAgeLimit = DateTime.now().minusYears(SOLE_TRADER_UPPER_AGE_LIMIT);
DateTime dateOfBirth = dateProducer.randomDateBetweenTwoDates(lowerAgeLimit, upperAgeLimit);
NationalIdentificationNumberProvider nationalIdentificationNumberProvider = nationalIdentificationNumberFactory.produceNationalIdentificationNumberProvider(
dateOfBirth(dateOfBirth));
String personalIdentityNumber = nationalIdentificationNumberProvider.get().getValue();
return SE + personalIdentityNumber.replace("-", "") + "01";
}
代码示例来源:origin: metatron-app/metatron-discovery
public List<DateTime> extractMinMaxTime() {
if(CollectionUtils.isEmpty(this.intervals)) {
DateTime now = DateTime.now();
return Lists.newArrayList(now.minusYears(5), now);
}
Interval firstInterval = Interval.parse(this.intervals.get(0));
if(this.intervals.size() == 1) {
return Lists.newArrayList(firstInterval.getStart(), firstInterval.getEnd());
}
Interval lastInterval = Interval.parse(this.intervals.get(this.intervals.size()-1));
return Lists.newArrayList(firstInterval.getStart(), lastInterval.getEnd());
}
代码示例来源:origin: org.restcomm.smpp/ch-commons-util
@Override
public DateTimePeriod getPrevious() {
DateTime previous = getStart().minusYears(1);
return DateTimePeriod.createYear(previous);
}
代码示例来源:origin: io.codearte.jfairy/jfairy
public DateTime randomDateInThePast(int maxYearsEarlier) {
checkArgument(maxYearsEarlier >= 0, "%s has to be >= 0", maxYearsEarlier);
DateTime currentDate = timeProvider.getCurrentDate();
DateTime latestDateInThePast = currentDate.minusSeconds(SECONDS_BEFORE_TO_BE_IN_THE_PAST);
DateTime maxYearsEarlierDate = currentDate.minusYears(maxYearsEarlier);
return randomDateBetweenTwoDates(maxYearsEarlierDate, latestDateInThePast);
}
代码示例来源:origin: camunda/camunda-bpm-platform
String testStringExpression = "${'" + expressionString + "'}";
Date queryDate = new DateTime(now()).minusYears(1).toDate();
String testDateExpression = "${now()}";
代码示例来源:origin: camunda/camunda-bpm-platform
String testStringExpression = "${'" + expressionString + "'}";
Date queryDate = new DateTime(now()).minusYears(1).toDate();
String testDateExpression = "${now()}";
内容来源于网络,如有侵权,请联系作者删除!