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

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

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

DateTime.plusWeeks介绍

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

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

The following three lines are identical in effect:

DateTime added = dt.plusWeeks(6); 
DateTime added = dt.plus(Period.weeks(6)); 
DateTime added = dt.withFieldAdded(DurationFieldType.weeks(), 6);

This datetime instance is immutable and unaffected by this method call.
[中]返回此datetime加上指定周数的副本。
该计算的操作方式就好像它在以天为单位添加等价物一样。
以下三行实际上是相同的:

DateTime added = dt.plusWeeks(6); 
DateTime added = dt.plus(Period.weeks(6)); 
DateTime added = dt.withFieldAdded(DurationFieldType.weeks(), 6);

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

代码示例

代码示例来源:origin: killbill/killbill

@Override
public DateTime addToDateTime(final DateTime dateTime) {
  if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
    return dateTime;
  }
  switch (unit) {
    case DAYS:
      return dateTime.plusDays(number);
    case WEEKS:
      return dateTime.plusWeeks(number);
    case MONTHS:
      return dateTime.plusMonths(number);
    case YEARS:
      return dateTime.plusYears(number);
    case UNLIMITED:
    default:
      throw new IllegalStateException("Unexpected duration unit " + unit);
  }
}

代码示例来源:origin: killbill/killbill

@Override
public DateTime addToDateTime(final DateTime dateTime) throws CatalogApiException {
  if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
    return dateTime;
  }
  switch (unit) {
    case DAYS:
      return dateTime.plusDays(number);
    case WEEKS:
      return dateTime.plusWeeks(number);
    case MONTHS:
      return dateTime.plusMonths(number);
    case YEARS:
      return dateTime.plusYears(number);
    case UNLIMITED:
    default:
      throw new CatalogApiException(ErrorCode.CAT_UNDEFINED_DURATION, unit);
  }
}

代码示例来源:origin: kairosdb/kairosdb

break;
case WEEKS:
  ret = new org.joda.time.Duration(dt, dt.plusWeeks((int) sampling.getValue())).getMillis();
  break;
case DAYS:

代码示例来源: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: prestodb/presto

@Test
public void testAddFieldToDate()
{
  assertFunction("date_add('day', 0, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE));
  assertFunction("date_add('day', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusDays(3)));
  assertFunction("date_add('week', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusWeeks(3)));
  assertFunction("date_add('month', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusMonths(3)));
  assertFunction("date_add('quarter', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusMonths(3 * 3)));
  assertFunction("date_add('year', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusYears(3)));
}

代码示例来源: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: prestodb/presto

@Test
public void testAddFieldToTimestamp()
{
  assertFunction("date_add('millisecond', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMillis(3), session));
  assertFunction("date_add('second', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusSeconds(3), session));
  assertFunction("date_add('minute', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMinutes(3), session));
  assertFunction("date_add('hour', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusHours(3), session));
  assertFunction("date_add('hour', 23, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusHours(23), session));
  assertFunction("date_add('hour', -4, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.minusHours(4), session));
  assertFunction("date_add('hour', -23, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.minusHours(23), session));
  assertFunction("date_add('day', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusDays(3), session));
  assertFunction("date_add('week', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusWeeks(3), session));
  assertFunction("date_add('month', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMonths(3), session));
  assertFunction("date_add('quarter', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMonths(3 * 3), session));
  assertFunction("date_add('year', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusYears(3), session));
  assertFunction("date_add('millisecond', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMillis(3)));
  assertFunction("date_add('second', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusSeconds(3)));
  assertFunction("date_add('minute', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMinutes(3)));
  assertFunction("date_add('hour', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusHours(3)));
  assertFunction("date_add('day', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusDays(3)));
  assertFunction("date_add('week', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusWeeks(3)));
  assertFunction("date_add('month', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3)));
  assertFunction("date_add('quarter', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3 * 3)));
  assertFunction("date_add('year', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusYears(3)));
}

代码示例来源:origin: xiaojianglaile/Calendar

public WeekView instanceWeekView(int position) {
  WeekView weekView = new WeekView(mContext, mArray, mStartDate.plusWeeks(position - mWeekCount / 2));
  weekView.setId(position);
  weekView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
  weekView.setOnWeekClickListener(mWeekCalendarView);
  weekView.invalidate();
  mViews.put(position, weekView);
  return weekView;
}

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

DateTime start = // whatever
DateTime end = // whatever

List<DateTime> datesBetween = new ArrayList<DateTime>();

while (start <= end) {
  datesBetween.add(start);
  DateTime dateBetween = start.plusWeeks(1);
  start = dateBetween;
}

代码示例来源:origin: ihaolin/antares

/**
 * 增加周
 * @param date 时间
 * @param numWeeks 周数
 * @return 时间
 */
public static Date addWeeks(Date date, int numWeeks) {
  return new DateTime(date).plusWeeks(numWeeks).toDate();
}

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

DateTimeZone zone = DateTimeZone( "America/Montreal" );
// Get first moment of a Monday. Inclusive.
DateTime start = new DateTime( 2014, 11, 24, 0, 0, 0, zone ); // Handle exception thrown if occurring during a Daylight Saving Time gap.
DateTime stop = start.plusWeeks( 1 ); // First moment of following Monday. Exclusive.
Interval week = new Interval ( start, stop );

代码示例来源:origin: me.hao0/common

/**
 * 增加周
 * @param date 时间
 * @param numWeeks 周数
 * @return 时间
 */
public static Date addWeeks(Date date, int numWeeks) {
  return new DateTime(date).plusWeeks(numWeeks).toDate();
}

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

DateTimeZone timeZone = DateTimeZone.forID( "Europe/Paris" );

DateTime now = new DateTime( timeZone );
DateTime firstWeekStart = now.withWeekOfWeekyear(1).withDayOfWeek( DateTimeConstants.MONDAY ).withTimeAtStartOfDay();
DateTime firstWeekStop = firstWeekStart.plusWeeks( 1 );
Interval firstWeek = new Interval( firstWeekStart, firstWeekStop );

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

DateTimeFormatter fmt = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss");
DateTime dt = fmt.parseDateTime(timestampin);

if (increment.equals("HOURLY")) {
  dt = dt.plusHours(1);
}
else if (increment.equals("DAILY")) {
  dt = dt.plusDays(1);
}
else  if (increment.equals("WEEKLY")) {
  dt = dt.plusWeeks(1);
}

String timestampOut = fmt.print(dt);

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

private Optional<OrderDates> resolveOrderDates(final Entity order) {
  Date plannedStart = order.getDateField(OrderFields.DATE_FROM);
  if (plannedStart == null) {
    return Optional.absent();
  }
  // Order realization end time is not required, thus I've passed some arbitrary values here.
  return Optional.of(OrderDates.of(order, new DateTime(plannedStart), new DateTime(plannedStart).plusWeeks(1)));
}

代码示例来源: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: FenixEdu/fenixedu-academic

public Interval getWeeklyWorkLoadInterval() {
  final DateTime beginningOfSemester = new DateTime(getBegginingOfLessonPeriod());
  final DateTime firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
  final DateTime endOfSemester = new DateTime(getEndOfExamsPeriod());
  final DateTime nextLastMonday = endOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1).plusWeeks(1);
  return new Interval(firstMonday, nextLastMonday);
}

代码示例来源:origin: FenixEdu/fenixedu-academic

public Interval getInterval() {
  final ExecutionSemester executionSemester = getExecutionPeriod();
  final DateTime beginningOfSemester = new DateTime(executionSemester.getBeginDateYearMonthDay());
  final DateTime firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
  final DateTime endOfSemester = new DateTime(executionSemester.getEndDateYearMonthDay());
  final DateTime nextLastMonday = endOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1).plusWeeks(1);
  return new Interval(firstMonday, nextLastMonday);
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

@Test
public void testAddFieldToDate()
{
  assertFunction("date_add('day', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusDays(3)));
  assertFunction("date_add('week', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusWeeks(3)));
  assertFunction("date_add('month', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusMonths(3)));
  assertFunction("date_add('quarter', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusMonths(3 * 3)));
  assertFunction("date_add('year', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusYears(3)));
}

代码示例来源:origin: io.prestosql/presto-main

@Test
public void testAddFieldToDate()
{
  assertFunction("date_add('day', 0, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE));
  assertFunction("date_add('day', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusDays(3)));
  assertFunction("date_add('week', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusWeeks(3)));
  assertFunction("date_add('month', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusMonths(3)));
  assertFunction("date_add('quarter', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusMonths(3 * 3)));
  assertFunction("date_add('year', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusYears(3)));
}

相关文章

DateTime类方法