本文整理了Java中org.joda.time.DateTime.minusMonths()
方法的一些代码示例,展示了DateTime.minusMonths()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.minusMonths()
方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:minusMonths
[英]Returns a copy of this datetime minus the specified number of months.
The calculation will do its best to only change the month field retaining the same day of month. However, in certain circumstances, it may be necessary to alter smaller fields. For example, 2007-05-31 minus one month cannot result in 2007-04-31, so the day of month is adjusted to 2007-04-30.
The following three lines are identical in effect:
DateTime subtracted = dt.minusMonths(6);
DateTime subtracted = dt.minus(Period.months(6));
DateTime subtracted = dt.withFieldAdded(DurationFieldType.months(), -6);
This datetime instance is immutable and unaffected by this method call.
[中]返回此datetime减去指定月数的副本。
计算将尽最大努力只更改保留当月同一天的月份字段。但是,在某些情况下,可能需要更改较小的字段。例如,2007-05-31减去一个月不能生成2007-04-31,因此将月份的日期调整为2007-04-30。
以下三行实际上是相同的:
DateTime subtracted = dt.minusMonths(6);
DateTime subtracted = dt.minus(Period.months(6));
DateTime subtracted = dt.withFieldAdded(DurationFieldType.months(), -6);
此datetime实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: apache/flume
if (fixed.isAfter(now) && fixed.minusMonths(1).isAfter(now)) {
fixed = date.minusYears(1);
代码示例来源:origin: apache/incubator-druid
@Test
public void testAppliesToPartialOverlap()
{
DateTime now = DateTimes.of("2012-12-31T01:00:00");
PeriodLoadRule rule = new PeriodLoadRule(
new Period("P1M"),
false,
ImmutableMap.of("", 0)
);
Assert.assertTrue(
rule.appliesTo(
builder.interval(new Interval(now.minusWeeks(1), now.plusWeeks(1))).build(),
now
)
);
Assert.assertTrue(
rule.appliesTo(
builder.interval(
new Interval(now.minusMonths(1).minusWeeks(1), now.minusMonths(1).plusWeeks(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: apache/incubator-druid
Assert.assertFalse(
rule.appliesTo(
builder.interval(new Interval(now.minusMonths(2), now.minusDays(1)))
.build(),
now
代码示例来源:origin: com.github.fosin/cdp-utils
/**
* getDatetimeOfLastMonth
*
* @return a {@link java.lang.String} object.
*/
public String getDatetimeOfLastMonth(){
DateTime dt = new DateTime();
return dt.minusMonths(1).toString("yyyy-MM-dd HH:mm:ss");
}
代码示例来源:origin: com.github.fosin/cdp-utils
/**
* get$datetimeOfLastMonth
*
* @return a {@link java.util.Date} object.
*/
public Date get$datetimeOfLastMonth(){
DateTime dt = new DateTime();
return dt.minusMonths(1).toDate();
}
代码示例来源:origin: org.modeshape/modeshape-graph
/**
* {@inheritDoc}
*
* @see org.modeshape.graph.property.DateTime#minusMonths(int)
*/
public org.modeshape.graph.property.DateTime minusMonths( int months ) {
return new JodaDateTime(this.instance.minusMonths(months));
}
代码示例来源:origin: stackoverflow.com
DateTime dt = new DateTime();
DateTime year2000 = dt.withYear(2000);
DateTime oneMonthBefore = dt.minusMonths(1);
DateTimeFormatter fmt = ...;
String d = dt.toString(fmt);
代码示例来源:origin: com.atlassian.jira/jira-core
public DateTime monthsIntoPast()
{
return DateTime.now().minusMonths(getNumberOfMonths());
}
代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core
/**
* Creates a new Period instance that matches all the instants between N months before the instantiation and the
* instantiation.
*
* @param numberOfMonths number of months to substract from current date
* @return The corresponding period object
*/
public static Period createSinceMonthsPeriod(int numberOfMonths)
{
DateTime dt = new DateTime();
return createPeriod(dt.minusMonths(numberOfMonths).getMillis(), dt.getMillis());
}
代码示例来源:origin: com.atlassian.addon.connect.hercules/hercules-ac
public static List<Long> findIssueKeysByPatternId(final Long issueId, final Long patternId)
{
List<BigInteger> queryResultList = (List<BigInteger>) JPA.em().createNativeQuery(findIssueIdQuery).setParameter("patternId", patternId).
setParameter("dateFrom", new DateTime().minusMonths(TIME_RANGE_FOR_SIMILAR_ISSUES).toDate()).setParameter("issueId", issueId).getResultList();
if (queryResultList.isEmpty())
{
return Collections.EMPTY_LIST;
}
List<Long> resultList = queryResultList.stream().mapToLong(BigInteger::longValue)
.collect(LinkedList::new, LinkedList::add, LinkedList::addAll);
return resultList;
}
代码示例来源: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: com.cloudhopper/ch-commons-util
@Override
public DateTimePeriod getPrevious() {
DateTime previous = getStart().minusMonths(1);
return DateTimePeriod.createMonth(previous);
}
代码示例来源:origin: org.restcomm.smpp/ch-commons-util
@Override
public DateTimePeriod getPrevious() {
DateTime previous = getStart().minusMonths(1);
return DateTimePeriod.createMonth(previous);
}
代码示例来源:origin: com.yahoo.maha/maha-par-request-2
public static int getPreviousMonthStartHourId(int currentHourId) {
return getHours(
new DateTime((long) currentHourId * 3600 * 1000, TimeUtil.EASTERN).minusMonths(1).withDayOfMonth(1)
.withTimeAtStartOfDay());
}
代码示例来源:origin: com.yahoo.maha/maha-par-request
public static int getPreviousMonthStartHourId(int currentHourId) {
return getHours(
new DateTime((long) currentHourId * 3600 * 1000, TimeUtil.EASTERN).minusMonths(1).withDayOfMonth(1)
.withTimeAtStartOfDay());
}
代码示例来源:origin: MegaMek/mekhq
@Override
public void actionPerformed(ActionEvent e) {
if((e.getModifiers() & ActionEvent.ALT_MASK) > 0) {
date = date.minusYears(1);
} else if((e.getModifiers() & ActionEvent.CTRL_MASK) > 0) {
date = date.minusMonths(1);
} else {
date = date.minusDays(1);
}
updateDate();
}
}), gbc);
代码示例来源:origin: dhis2/dhis2-core
@Override
public DateTimeUnit minusMonths( DateTimeUnit dateTimeUnit, int months )
{
DateTime dateTime = dateTimeUnit.toJodaDateTime( chronology );
return DateTimeUnit.fromJodaDateTime( dateTime.minusMonths( months ), dateTimeUnit.isIso8601() );
}
代码示例来源:origin: TUM-Dev/Campus-Android
/**
* Several items with different sources, including selected newspread
* Expected output: several items are retrieved
*/
@Test
public void getAllSelectedSourceTest() {
DateTime now = DateTime.now();
dao.insert(createNewsItem("999", now.minusMonths(5)));
dao.insert(createNewsItem("999", now.minusDays(100)));
dao.insert(createNewsItem("125", now.minusMonths(1)));
dao.insert(createNewsItem("999", now));
assertThat(dao.getAll(new Integer[]{123, 999}, 999)).hasSize(3);
}
代码示例来源:origin: TUM-Dev/Campus-Android
/**
* All dates are in the past for news items
* Expected output: No items retrieved
*/
@Test
public void getNewerNoneTest() {
DateTime now = DateTime.now();
dao.insert(createNewsItem("123", now.minusDays(1)));
dao.insert(createNewsItem("123", now.minusMonths(1)));
dao.insert(createNewsItem("123", now.minusYears(1)));
dao.insert(createNewsItem("123", now.minusHours(1)));
assertThat(dao.getNewer(123)).hasSize(0);
}
内容来源于网络,如有侵权,请联系作者删除!