org.joda.time.DateTime.minusWeeks()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(174)

本文整理了Java中org.joda.time.DateTime.minusWeeks()方法的一些代码示例,展示了DateTime.minusWeeks()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.minusWeeks()方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:minusWeeks

DateTime.minusWeeks介绍

[英]Returns a copy of this datetime minus the specified number of weeks.

The calculation operates as if it were subtracting the equivalent in days.

The following three lines are identical in effect:

DateTime subtracted = dt.minusWeeks(6); 
DateTime subtracted = dt.minus(Period.weeks(6)); 
DateTime subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6);

This datetime instance is immutable and unaffected by this method call.
[中]返回此datetime减去指定周数的副本。
计算的过程就好像是用天减去等价物一样。
以下三行实际上是相同的:

DateTime subtracted = dt.minusWeeks(6); 
DateTime subtracted = dt.minus(Period.weeks(6)); 
DateTime subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6);

此datetime实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: apache/incubator-druid

@Test
public void testAppliesToPeriod()
{
 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)).build(), now));
 Assert.assertTrue(
   rule.appliesTo(
     builder.interval(new Interval(now.minusDays(1), now.plusDays(1)))
         .build(),
     now
   )
 );
 Assert.assertFalse(
   rule.appliesTo(
     builder.interval(new Interval(now.plusDays(1), now.plusDays(2)))
           .build(),
     now
   )
 );
}

代码示例来源: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: apache/incubator-druid

builder.interval(new Interval(now.minusWeeks(1), now.minusDays(1)))
      .build(),
now

代码示例来源:origin: dlew/joda-time-android

assertEquals(DateUtils.formatDateTime(ctx, DateTime.now().plusWeeks(1), flags),
  DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().plusWeeks(1)));
assertEquals(DateUtils.formatDateTime(ctx, DateTime.now().minusWeeks(1), flags),
  DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusWeeks(1)));

代码示例来源:origin: stackoverflow.com

DateTime getFirstDayOfWeek(DateTime other) {
 if(other.dayOfWeek.get == 7)
  return other;
 else
  return other.minusWeeks(1).withDayOfWeek(7);
}

代码示例来源:origin: stackoverflow.com

DateTimeZone zone = DateTimeZone.forID( "America/Montral" );
DateTime now = DateTime.now( zone );
DateTime then = now.minusWeeks( 1 );  // Arbitrarily creating a moment in the past.
Interval interval = new Interval( then , now );  // Interval is a pair of moments on the timeline defining a span of time.
int days = Days.daysIn( interval ).getDays();  // First call returns `Days` object. Second call extracts the simple integer number of days as an `int`.

代码示例来源:origin: stackoverflow.com

DateTime dt = new DateTime();
System.out.println(dt);
System.out.println(dt.minusWeeks(12));
System.out.println(dt.minusWeeks(12).toDate());//if you prefer Date object

代码示例来源:origin: stackoverflow.com

final DateTime input = new DateTime();
System.out.println(input);
final DateMidnight startOfLastWeek = 
  new DateMidnight(input.minusWeeks(1).withDayOfWeek(DateTimeConstants.MONDAY));
System.out.println(startOfLastWeek);
final DateMidnight endOfLastWeek = startOfLastWeek.plusDays(6);
System.out.println(endOfLastWeek);

代码示例来源:origin: org.n52.sensorweb/timeseries-io

private IntervalWithTimeZone createDefaultTimespan() {
  DateTime now = new DateTime();
  DateTime lastWeek = now.minusWeeks(1);
  String interval = lastWeek
      .toString()
      .concat("/")
      .concat(now.toString());
  return new IntervalWithTimeZone(interval);
}

代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core

/**
 * Creates a new Period instance that matches all the instants between N weeks before the instantiation and the
 * instantiation.
 * 
 * @param numberOfWeeks number of weeks to substract from current date
 * @return The corresponding period object
 */
public static Period createSinceWeeksPeriod(int numberOfWeeks)
{
  DateTime dt = new DateTime();
  return createPeriod(dt.minusWeeks(numberOfWeeks).getMillis(), dt.getMillis());
}

代码示例来源:origin: org.modeshape/modeshape-graph

/**
 * {@inheritDoc}
 * 
 * @see org.modeshape.graph.property.DateTime#minusWeeks(int)
 */
public org.modeshape.graph.property.DateTime minusWeeks( int weeks ) {
  return new JodaDateTime(this.instance.minusWeeks(weeks));
}

代码示例来源:origin: stackoverflow.com

DateTime now = new DateTime(DateTimeZone.forID("UTC"));
DateTime saturday = now.withDayOfWeek(6);
if (saturday.isAfter(now)) {
  saturday = saturday .minusWeeks(1);
}
System.out.println(saturday);

代码示例来源:origin: org.n52.series-api/spi

public static IntervalWithTimeZone createDefaultTimespan() {
  DateTime now = new DateTime();
  // TODO make this configurable
  DateTime lastWeek = now.minusWeeks(1);
  String interval = lastWeek.toString()
               .concat("/")
               .concat(now.toString());
  return new IntervalWithTimeZone(interval);
}

代码示例来源:origin: stackoverflow.com

import org.joda.time.DateTime;
public class Test {

  public static void main(String[] args) {

    DateTime today = new DateTime();
    DateTime nextWeek = today.plusWeeks(1);
    DateTime lastWeek = today.minusWeeks(1);
    System.out.println("Last Week: " + lastWeek.toString("MM/dd/yyyy"));
    System.out.println("Today: " + today.toString("MM/dd/yyyy"));
    System.out.println("Next Week: " + nextWeek.toString("MM/dd/yyyy"));

  }
}

代码示例来源:origin: org.n52.sensorweb/timeseries-io

private String createDefaultTimespan() {
  DateTime now = new DateTime();
  DateTime lastWeek = now.minusWeeks(1);
  String interval = lastWeek
               .toString()
               .concat("/")
               .concat(now.toString());
  return new IntervalWithTimeZone(interval).toString();
}

代码示例来源:origin: stackoverflow.com

DateTimeZone timeZone = DateTimeZone.forID( "America/New_York" );
DateTime now = new DateTime( timeZone );

DateTime weekStart = now.withDayOfWeek( DateTimeConstants.SUNDAY ).withTimeAtStartOfDay();
if ( now.isBefore( weekStart )) {
  // If we got next Sunday, go back one week to last Sunday.
  weekStart = weekStart.minusWeeks( 1 );
}
DateTime weekEnd = weekStart.plusWeeks( 1 );
Interval week = new Interval( weekStart, weekEnd );

代码示例来源:origin: org.n52.sensorweb/sensorwebclient-sos-rest

private String createDefaultTimespan() {
  DateTime now = new DateTime();
  DateTime lastWeek = now.minusWeeks(1);
  return new Interval(lastWeek, now).toString();
}

代码示例来源:origin: stackoverflow.com

DateTime today = DateTime.now();
DateTime sameDayLastWeek = today.minusWeeks(1);
DateTime mondayLastWeek = sameDayLastWeek.withDayOfWeek(DateTimeConstants.MONDAY);
DateTime fridayLastWeek = sameDayLastWeek.withDayOfWeek(DateTimeConstants.FRIDAY);

代码示例来源:origin: qcadoo/mes

@Async
@Scheduled(cron = CRON_EVERYDAY_AT_5AM)
@RunIfEnabled(TechnologiesGeneratorConstants.PLUGIN_IDENTIFIER)
public void performCleanUp() {
  DateTime threshold = DateTime.now().minusWeeks(1);
  Either<EntityMessagesHolder, List<ContextId>> result = generatorContextDataProvider.deleteContextsNotUsedSince(threshold);
  if (result.isLeft()) {
    warn(String.format("CleanUp aborted - Technology generator context couldn't be deleted: %s", result.getLeft()));
  } else {
    info(String.format("CleanUp done - %s technology generator contexts were deleted.", result.getRight().size()));
  }
}

代码示例来源:origin: dhis2/dhis2-core

@Override
public DateTimeUnit minusWeeks( DateTimeUnit dateTimeUnit, int weeks )
{
  DateTime dateTime = dateTimeUnit.toJodaDateTime( chronology );
  return DateTimeUnit.fromJodaDateTime( dateTime.minusWeeks( weeks ), dateTimeUnit.isIso8601() );
}

相关文章

DateTime类方法