java.util.Calendar.roll()方法的使用及代码示例

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

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

Calendar.roll介绍

[英]Adds the given amount to the given field and wraps the value of the field when it goes beyond the maximum or minimum value for the current date. Other fields will be adjusted as required to maintain a consistent date.
[中]将给定金额添加到给定字段,并在字段值超出当前日期的最大值或最小值时包装字段值。其他字段将根据需要进行调整,以保持一致的日期。

代码示例

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

/**
 * Adds the given amount to the given field and wraps the value of
 * the field when it goes beyond the maximum or minimum value for the
 * current date. Other fields will be adjusted as required to maintain a
 * consistent date.
 */
public void roll(int field, int value) {
  boolean increment = value >= 0;
  int count = increment ? value : -value;
  for (int i = 0; i < count; i++) {
    roll(field, increment);
  }
}

代码示例来源:origin: ankidroid/Anki-Android

public static long getDayStart() {
  Calendar cal = Calendar.getInstance();
  if (cal.get(Calendar.HOUR_OF_DAY) < 4) {
    cal.roll(Calendar.DAY_OF_YEAR, -1);
  }
  cal.set(Calendar.HOUR_OF_DAY, 4);
  cal.set(Calendar.MINUTE, 0);
  cal.set(Calendar.SECOND, 0);
  cal.set(Calendar.MILLISECOND, 0);
  return cal.getTimeInMillis();
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 描述:获取本月最后一天.
 *
 * @param format the format
 * @return String String类型日期时间
 */
public static String getLastDayOfMonth(String format) {
  String strDate = null;
  try {
    Calendar c = new GregorianCalendar();
    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
    // 当前月的最后一天
    c.set(Calendar.DATE, 1);
    c.roll(Calendar.DATE, -1);
    strDate = mSimpleDateFormat.format(c.getTime());
  } catch (Exception e) {
    e.printStackTrace();
  }
  return strDate;
}

代码示例来源:origin: kiegroup/jbpm

private Calendar randomCal() { 
  Calendar cal = GregorianCalendar.getInstance();
  cal.roll(Calendar.DAY_OF_YEAR, -1*random.nextInt(10*365));
  cal.set(Calendar.MILLISECOND, 0);
  cal.set(Calendar.SECOND, 0);
  return cal;
}

代码示例来源:origin: kiegroup/jbpm

static Calendar randomCal() { 
  Calendar cal = GregorianCalendar.getInstance();
  cal.roll(Calendar.DAY_OF_YEAR, -1*random.nextInt(10*365));
  cal.set(Calendar.MILLISECOND, 0);
  cal.set(Calendar.SECOND, 0);
  return cal;
}

代码示例来源:origin: kiegroup/jbpm

private Calendar randomCal() { 
  Calendar cal = GregorianCalendar.getInstance();
  cal.roll(Calendar.DAY_OF_YEAR, -1*random.nextInt(10*365));
  cal.set(Calendar.MILLISECOND, 0);
  cal.set(Calendar.SECOND, 0);
  cal.set(Calendar.MINUTE, 0);
  cal.set(Calendar.HOUR_OF_DAY, 0);
  return cal;
}

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

/**
 * Returns the minimum value of the given field for the current date.
 */
public int getActualMinimum(int field) {
  int value, next;
  if (getMinimum(field) == (next = getGreatestMinimum(field))) {
    return next;
  }
  complete();
  long orgTime = time;
  set(field, next);
  do {
    value = next;
    roll(field, false);
    next = get(field);
  } while (next < value);
  time = orgTime;
  areFieldsSet = false;
  return value;
}

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

/**
 * Returns the maximum value of the given field for the current date.
 * For example, the maximum number of days in the current month.
 */
public int getActualMaximum(int field) {
  int value, next;
  if (getMaximum(field) == (next = getLeastMaximum(field))) {
    return next;
  }
  complete();
  long orgTime = time;
  set(field, next);
  do {
    value = next;
    roll(field, true);
    next = get(field);
  } while (next > value);
  time = orgTime;
  areFieldsSet = false;
  return value;
}

代码示例来源:origin: ACRA/acra

calendar.roll(Calendar.MINUTE, -config.dropboxCollectionMinutes());
final long time = calendar.getTimeInMillis();
dateFormat.format(calendar.getTime());

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

public static String formatDateRange(Locale locale, TimeZone tz, long startMs, long endMs, int flags) {
 Calendar startCalendar = Calendar.getInstance(tz);
 startCalendar.setTimeInMillis(startMs);
 Calendar endCalendar;
 if (startMs == endMs) {
  endCalendar = startCalendar;
 } else {
  endCalendar = Calendar.getInstance(tz);
  endCalendar.setTimeInMillis(endMs);
 }
 boolean endsAtMidnight = isMidnight(endCalendar);
 // If we're not showing the time or the start and end times are on the same day, and the
 // end time is midnight, fudge the end date so we don't count the day that's about to start.
 // This is not the behavior of icu4c's DateIntervalFormat, but it's the historical behavior
 // of Android's DateUtils.formatDateRange.
 if (startMs != endMs && endsAtMidnight &&
   ((flags & FORMAT_SHOW_TIME) == 0 || julianDay(startCalendar) == julianDay(endCalendar))) {
  endCalendar.roll(Calendar.DAY_OF_MONTH, false);
  endMs -= DAY_IN_MS;
 }
 String skeleton = toSkeleton(startCalendar, endCalendar, flags);
 synchronized (CACHED_FORMATTERS) {
  return formatDateInterval(getFormatter(skeleton, locale.toString(), tz.getID()), startMs, endMs);
 }
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void doesContinueWithFilterChain_IfClientSecretNotExpired() throws IOException, ServletException, ParseException {
  BaseClientDetails clientDetails = new BaseClientDetails("client-1", "none", "uaa.none", "client_credentials",
      "http://localhost:5000/uaadb" );
  Calendar previousDay = Calendar.getInstance();
  previousDay.roll(Calendar.DATE, -1);
  clientDetails.setAdditionalInformation(createTestAdditionalInformation(previousDay));
  when(clientDetailsService.loadClientByClientId(Mockito.matches("app"))).thenReturn(clientDetails);
  UsernamePasswordAuthentication authResult =
      new UsernamePasswordAuthentication("app","appclientsecret");
  authResult.setAuthenticated(true);
  when(clientAuthenticationManager.authenticate(any())).thenReturn(authResult);
  MockFilterChain chain = mock(MockFilterChain.class);
  MockHttpServletRequest request = new MockHttpServletRequest();
  request.addHeader("Authorization", "Basic " + CREDENTIALS_HEADER_STRING);
  MockHttpServletResponse response = new MockHttpServletResponse();
  filter.doFilter(request, response, chain);
  verify(clientAuthenticationManager).authenticate(any(Authentication.class));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
  public void testTime() {
    final TimeFilter filter = TimeFilter.createFilter("02:00:00", "03:00:00", "America/LosAngeles", null, null);
    filter.start();
    assertTrue(filter.isStarted());
    final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/LosAngeles"));
    cal.set(Calendar.HOUR_OF_DAY, 2);
    CLOCKTIME = cal.getTimeInMillis();
    LogEvent event = Log4jLogEvent.newBuilder().setTimeMillis(CLOCKTIME).build();
    assertSame(Filter.Result.NEUTRAL, filter.filter(null, Level.ERROR, null, (Object) null, (Throwable) null));
    assertSame(Filter.Result.NEUTRAL, filter.filter(event));

    cal.roll(Calendar.DAY_OF_MONTH, true);
    CLOCKTIME = cal.getTimeInMillis();
    event = Log4jLogEvent.newBuilder().setTimeMillis(CLOCKTIME).build();
    assertSame(Filter.Result.NEUTRAL, filter.filter(event));
    assertSame(Filter.Result.NEUTRAL, filter.filter(null, Level.ERROR, null, (Object) null, (Throwable) null));

    cal.set(Calendar.HOUR_OF_DAY, 4);
    CLOCKTIME = cal.getTimeInMillis();
    event = Log4jLogEvent.newBuilder().setTimeMillis(CLOCKTIME).build();
    assertSame(Filter.Result.DENY, filter.filter(null, Level.ERROR, null, (Object) null, (Throwable) null));
    assertSame(Filter.Result.DENY, filter.filter(event));
  }
}

代码示例来源:origin: kiegroup/jbpm

cal.roll(Calendar.SECOND, 1);
testData[i] = new VariableInstanceLog(23L, "org.lots.of.vars", "inst", "first-var", "val-a", "oldVal-" + i);
testData[i+5] = new VariableInstanceLog(23L, "org.lots.of.vars", "inst", "second-var", "val-b", "oldVal-" + i);

代码示例来源:origin: matyb/java-koans

@Koan
public void usingRollToChangeDatesDoesntWrapOtherFields() {
  Calendar cal = Calendar.getInstance();
  cal.setTime(date);
  cal.roll(Calendar.MONTH, 12);
  assertEquals(cal.getTime().toString(), __);
}

代码示例来源:origin: pentaho/mondrian

final int roll = firstDayOfWeek - dow;
  assert roll < 0;
  calendar.roll(Calendar.DAY_OF_WEEK, roll);
} else {
  final int roll = firstDayOfWeek - dow - 7;
  assert roll < 0;
  calendar.roll(Calendar.DAY_OF_WEEK, roll);

代码示例来源:origin: apache/cloudstack

long endDate = 0;
if (_aggregationDuration == DAILY_TIME) {
  cal.roll(Calendar.DAY_OF_YEAR, false);
  cal.set(Calendar.HOUR_OF_DAY, 0);
  cal.set(Calendar.MINUTE, 0);
  startDate = cal.getTime().getTime();
  cal.roll(Calendar.DAY_OF_YEAR, true);
  cal.add(Calendar.MILLISECOND, -1);
  endDate = cal.getTime().getTime();
} else if (_aggregationDuration == HOURLY_TIME) {
  cal.roll(Calendar.HOUR_OF_DAY, false);
  cal.set(Calendar.MINUTE, 0);
  cal.set(Calendar.SECOND, 0);
  startDate = cal.getTime().getTime();
  cal.roll(Calendar.HOUR_OF_DAY, true);
  cal.add(Calendar.MILLISECOND, -1);
  endDate = cal.getTime().getTime();

代码示例来源:origin: kiegroup/jbpm

cal.roll(Calendar.SECOND, 1);
testData[i] = new VariableInstanceLog(randomLong(), processId, "varInstId", "var-" +i, "val-"+i, "oldVal-" + i);

代码示例来源:origin: apache/cloudstack

cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.roll(Calendar.DAY_OF_YEAR, true);
cal.add(Calendar.MILLISECOND, -1);
aggDate = cal.getTime().getTime();
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.roll(Calendar.HOUR_OF_DAY, true);
cal.add(Calendar.MILLISECOND, -1);
aggDate = cal.getTime().getTime();

代码示例来源:origin: apache/cloudstack

_jobExecTime.roll(Calendar.DAY_OF_YEAR, true);

代码示例来源:origin: camunda/camunda-bpm-platform

@Deployment(resources={"org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testTaskDueDate() throws Exception {
 ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
 Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
 // Set due-date on task
 Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
 task.setDueDate(dueDate);
 taskService.saveTask(task);
 assertEquals(1, taskService.createTaskQuery().dueDate(dueDate).count());
 Calendar otherDate = Calendar.getInstance();
 otherDate.add(Calendar.YEAR, 1);
 assertEquals(0, taskService.createTaskQuery().dueDate(otherDate.getTime()).count());
 Calendar priorDate = Calendar.getInstance();
 priorDate.setTime(dueDate);
 priorDate.roll(Calendar.YEAR, -1);
 assertEquals(1, taskService.createTaskQuery().dueAfter(priorDate.getTime())
   .count());
 assertEquals(1, taskService.createTaskQuery()
   .dueBefore(otherDate.getTime()).count());
}

相关文章