当前位置: 首页>>代码示例>>Java>>正文


Java Calendar.before方法代码示例

本文整理汇总了Java中java.util.Calendar.before方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.before方法的具体用法?Java Calendar.before怎么用?Java Calendar.before使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Calendar的用法示例。


在下文中一共展示了Calendar.before方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setDate

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * This method set a current and selected date of the calendar using Calendar object.
 *
 * @param date A Calendar object representing a date to which the calendar will be set
 */
public void setDate(Calendar date) throws OutOfDateRangeException {
    if (mCalendarProperties.getMinimumDate() != null && date.before(mCalendarProperties.getMinimumDate())) {
        throw new OutOfDateRangeException("SET DATE EXCEEDS THE MINIMUM DATE");
    }

    if (mCalendarProperties.getMaximumDate() != null && date.after(mCalendarProperties.getMaximumDate())) {
        throw new OutOfDateRangeException("SET DATE EXCEEDS THE MAXIMUM DATE");
    }

    DateUtils.setMidnight(date);

    mCalendarProperties.getSelectedDate().setTime(date.getTime());

    mCalendarProperties.getCurrentDate().setTime(date.getTime());
    mCalendarProperties.getCurrentDate().add(Calendar.MONTH, -FIRST_VISIBLE_PAGE);
    mCurrentMonthLabel.setText(DateUtils.getMonthAndYearDate(mContext, date));

    mViewPager.setCurrentItem(FIRST_VISIBLE_PAGE);
    mCalendarPageAdapter.notifyDataSetChanged();
}
 
开发者ID:Applandeo,项目名称:Material-Calendar-View,代码行数:26,代码来源:CalendarView.java

示例2: determineStartTimeForFactorCalculation

import java.util.Calendar; //导入方法依赖的package包/类
private Calendar determineStartTimeForFactorCalculation(
        PricingPeriod pricingPeriod, Calendar chargedPeriodStart,
        long usagePeriodStart, boolean adjustUsagePeriodStart) {
    Calendar startTime;
    if (adjustUsagePeriodStart) {
        startTime = PricingPeriodDateConverter.getStartTime(
                usagePeriodStart, pricingPeriod);
    } else {
        startTime = Calendar.getInstance();
        startTime.setTimeInMillis(usagePeriodStart);
    }

    if (startTime.before(chargedPeriodStart)) {
        return chargedPeriodStart;
    } else {
        return startTime;
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:CostCalculatorPerUnit.java

示例3: compare

import java.util.Calendar; //导入方法依赖的package包/类
public int compare(Calendar x, Calendar y) {
	if ( x.before( y ) ) {
		return -1;
	}
	if ( x.after( y ) ) {
		return 1;
	}
	return 0;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:CalendarComparator.java

示例4: checkAlarm

import java.util.Calendar; //导入方法依赖的package包/类
private void checkAlarm(Calendar alarm) {
    Calendar now = Calendar.getInstance();
    if (alarm.before(now)) {
        long alarmForFollowingDay = alarm.getTimeInMillis() + 86400000L;
        alarm.setTimeInMillis(alarmForFollowingDay);
    }
}
 
开发者ID:BracketCove,项目名称:PosTrainer,代码行数:8,代码来源:AlarmService.java

示例5: dateDiff

import java.util.Calendar; //导入方法依赖的package包/类
private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future) {
	int diff = 0;
	long savedDate = fromDate.getTimeInMillis();
	while (future ? !fromDate.after(toDate) : !fromDate.before(toDate)) {
		savedDate = fromDate.getTimeInMillis();
		fromDate.add(type, future ? 1 : -1);
		diff++;
	}
	diff--;
	fromDate.setTimeInMillis(savedDate);
	return diff;
}
 
开发者ID:jiongjionger,项目名称:NeverLag,代码行数:13,代码来源:DateUtils.java

示例6: getUserAge

import java.util.Calendar; //导入方法依赖的package包/类
public static int getUserAge(Date birthday) {
    if(birthday == null) {
        return 0;
    } else {
        Calendar cal = Calendar.getInstance();
        if(cal.before(birthday)) {
            return 0;
        } else {
            int yearNow = cal.get(1);
            cal.setTime(birthday);
            int yearBirth = cal.get(1);
            return yearNow - yearBirth;
        }
    }
}
 
开发者ID:ZHENFENG13,项目名称:My-Blog,代码行数:16,代码来源:DateKit.java

示例7: enableAlert

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Enables an alarm using preferences and default values.
 * @param ctx Context, used to create a pending intent for receiving alarm and setting the alarm
 */
public static void enableAlert(Context ctx) {
    initiateFields(ctx);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        registerChannel(ctx);
    }

    String alertTime = PreferenceUtil.getAlertTimePreference(ctx);
    int alertHour = TimePreference.parseHour(alertTime);
    int alertMinute = TimePreference.parseMinute(alertTime);

    // create calendar instance for calculating alert time
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    // set alert time fields
    calendar.set(Calendar.HOUR_OF_DAY, alertHour);
    calendar.set(Calendar.MINUTE, alertMinute);
    calendar.set(Calendar.SECOND, 0);

    // if alert hour is before current time, push it forward by a day
    Calendar now = Calendar.getInstance();
    now.setTime(new Date());
    if (calendar.before(now)) {
        calendar.add(Calendar.DATE, 1);
    }

    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingAlertReceiver);
}
 
开发者ID:kfaryarok,项目名称:kfaryarok-android,代码行数:33,代码来源:AlertHelper.java

示例8: getSoFarWentHours

import java.util.Calendar; //导入方法依赖的package包/类
public static int getSoFarWentHours(long time1, long time2) {
	Calendar st = Calendar.getInstance();
	st.setTimeInMillis(time1);

	Calendar now = Calendar.getInstance();
	now.setTimeInMillis(time2);


	if (now.before(st)) {
		Calendar tmp = now;
		now = st;
		st = tmp;
	}

	st.clear(Calendar.MILLISECOND);
	st.clear(Calendar.SECOND);
	st.clear(Calendar.MINUTE);

	int diffHour = 0;
	Calendar cloneSt = (Calendar) st.clone();
	while(cloneSt.before(now))
	{
		cloneSt.add(Calendar.HOUR, 1);
		diffHour++;
	}

	if(diffHour != 0)
	{
		return diffHour - 1;
	}
	else
	{
		return diffHour;
	}
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:36,代码来源:TimeUtils.java

示例9: compareCalendar

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * @return 0 if cal1 and cal2 are in the same day; 1 if cal1 happens before cal2; -1 otherwise.
 */
private static int compareCalendar(Calendar cal1, Calendar cal2) {
    boolean sameDay = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
    if (sameDay) {
        return 0;
    } else if (cal1.before(cal2)) {
        return 1;
    } else {
        return -1;
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:15,代码来源:DateDividedAdapter.java

示例10: Test4738710

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 4738710: API: Calendar comparison methods should be improved
 */
public void Test4738710() {
    Calendar cal0 = new GregorianCalendar(2003, SEPTEMBER, 30);
    Comparable<Calendar> cal1 = new GregorianCalendar(2003, OCTOBER, 1);
    Calendar cal2 = new GregorianCalendar(2003, OCTOBER, 2);
    if (!(cal1.compareTo(cal0) > 0)) {
        errln("!(cal1 > cal0)");
    }
    if (!(cal1.compareTo(cal2) < 0)) {
        errln("!(cal1 < cal2)");
    }
    if (cal1.compareTo(new GregorianCalendar(2003, OCTOBER, 1)) != 0) {
        errln("cal1 != new GregorianCalendar(2003, OCTOBER, 1)");
    }

    if (cal0.after(cal2)) {
        errln("cal0 shouldn't be after cal2");
    }
    if (cal2.before(cal0)) {
        errln("cal2 shouldn't be before cal0");
    }

    if (cal0.after(0)) {
        errln("cal0.after() returned true with an Integer.");
    }
    if (cal0.before(0)) {
        errln("cal0.before() returned true with an Integer.");
    }
    if (cal0.after(null)) {
        errln("cal0.after() returned true with null.");
    }
    if (cal0.before(null)) {
        errln("cal0.before() returned true with null.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:CalendarRegression.java

示例11: days

import java.util.Calendar; //导入方法依赖的package包/类
public List<CalendarDay> days() {
    List<CalendarDay> calendarDays = new ArrayList<>();
    Calendar from = Calendar.getInstance();
    this.from.copyTo(from);
    Calendar to = Calendar.getInstance();
    this.to.copyTo(to);

    while (from.before(to) || from.equals(to)) {
        calendarDays.add(CalendarDay.from(from));
        from.add(Calendar.DAY_OF_YEAR, 1);
    }

    return calendarDays;
}
 
开发者ID:ptrstovka,项目名称:calendarview2,代码行数:15,代码来源:Range.java

示例12: isNowBetween

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 判断当前时间是否在两个时间段之内
 *
 * @param beginTime 开始时间
 * @param endTime   结束时间
 * @return
 */
public static boolean isNowBetween(String beginTime, String endTime) {
    SimpleDateFormat df = new SimpleDateFormat("HH:mm");
    Date now = null;
    Date begin = null;
    Date end = null;
    try {
        now = df.parse(df.format(new Date()));
        begin = df.parse(beginTime);
        end = df.parse(endTime);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Calendar nowCal = Calendar.getInstance();
    nowCal.setTime(now);

    Calendar beginCal = Calendar.getInstance();
    beginCal.setTime(begin);

    Calendar endCal = Calendar.getInstance();
    endCal.setTime(end);

    if (nowCal.after(beginCal) && nowCal.before(endCal)) {
        return true;
    } else {
        return false;
    }
}
 
开发者ID:li-yu,项目名称:FakeWeather,代码行数:35,代码来源:TimeUtils.java

示例13: isBetweenMinAndMax

import java.util.Calendar; //导入方法依赖的package包/类
private boolean isBetweenMinAndMax(Calendar day) {
    return !((mCalendarProperties.getMinimumDate() != null && day.before(mCalendarProperties.getMinimumDate()))
            || (mCalendarProperties.getMaximumDate() != null && day.after(mCalendarProperties.getMaximumDate())));
}
 
开发者ID:Applandeo,项目名称:Material-Calendar-View,代码行数:5,代码来源:DayRowClickListener.java

示例14: refreshNotifyBar

import java.util.Calendar; //导入方法依赖的package包/类
private void refreshNotifyBar() {
  final NotificationManager manager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  // Recursive trigger.
  final PendingIntent tick = PendingIntent.getService(
      this, 0, new Intent(this, AlarmNotificationService.class)
      .putExtra(AlarmNotificationService.COMMAND,
                AlarmNotificationService.REFRESH), 0);

  final Cursor c = getContentResolver().query(
      AlarmClockProvider.ALARMS_URI,
      new String[] { AlarmClockProvider.AlarmEntry.TIME,
                     AlarmClockProvider.AlarmEntry.ENABLED,
                     AlarmClockProvider.AlarmEntry.NAME,
                     AlarmClockProvider.AlarmEntry.DAY_OF_WEEK,
                     AlarmClockProvider.AlarmEntry.NEXT_SNOOZE },
      AlarmClockProvider.AlarmEntry.ENABLED + " == 1",
      null, null);

  // Clear notification bar when there are no alarms enabled or when there
  // is an alarm currently firing (that alarm will create its own
  // notification), or when the setting is disabled.
  if (c.getCount() == 0 ||
      (activeAlarms != null && !activeAlarms.alarmids.isEmpty()) ||
      PreferenceManager.getDefaultSharedPreferences(this)
      .getBoolean(DISPLAY_NOTIFICATION, true) == false) {
    ((AlarmManager)getSystemService(Context.ALARM_SERVICE)).cancel(tick);
    manager.cancel(NEXT_ALARM_NOTIFICATION_ID);
    c.close();
    return;
  }

  // Find the next alarm.
  final Calendar now = Calendar.getInstance();
  Calendar next = null;
  String next_label = "";
  while (c.moveToNext()) {
    final DbUtil.Alarm a = new DbUtil.Alarm(c);
    final Calendar n =
      TimeUtil.nextOccurrence(now, a.time, a.repeat, a.next_snooze);
    if (next == null || n.before(next)) {
      next = n;
      next_label = a.label;
    }
  }
  c.close();

  // Build notification and display it.
  manager.notify(
      NEXT_ALARM_NOTIFICATION_ID,
      new Notification.Builder(this)
      .setContentTitle(next_label.isEmpty() ?
                       getString(R.string.app_name) :
                       next_label)
      .setContentText(TimeUtil.formatLong(this, next) + " : " +
                      TimeUtil.until(getApplicationContext(), next))
      .setSmallIcon(R.drawable.ic_alarm)
      .setCategory(Notification.CATEGORY_STATUS)
      .setVisibility(Notification.VISIBILITY_PUBLIC)
      .setOngoing(true)
      .setContentIntent(
          PendingIntent.getActivity(
              this, 0, new Intent(this, AlarmClockActivity.class), 0))
      .build());

  // Schedule an update for the notification on the next minute.
  final Calendar wake = TimeUtil.nextMinute();
  ((AlarmManager)getSystemService(Context.ALARM_SERVICE)).setExact(
      AlarmManager.RTC, wake.getTimeInMillis(), tick);
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:71,代码来源:AlarmNotificationService.java

示例15: doSelectDate

import java.util.Calendar; //导入方法依赖的package包/类
private boolean doSelectDate(Date date, MonthCellDescriptor cell) {
  Calendar newlySelectedCal = Calendar.getInstance(timeZone, locale);
  newlySelectedCal.setTime(date);
  // Sanitize input: clear out the hours/minutes/seconds/millis.
  setMidnight(newlySelectedCal);

  // Clear any remaining range state.
  for (MonthCellDescriptor selectedCell : selectedCells) {
    selectedCell.setRangeState(RangeState.NONE);
  }

  switch (selectionMode) {
    case RANGE:
      if (selectedCals.size() > 1) {
        // We've already got a range selected: clear the old one.
        clearOldSelections();
      } else if (selectedCals.size() == 1 && newlySelectedCal.before(selectedCals.get(0))) {
        // We're moving the start of the range back in time: clear the old start date.
        clearOldSelections();
      }
      break;

    case MULTIPLE:
      date = applyMultiSelect(date, newlySelectedCal);
      break;

    case SINGLE:
      clearOldSelections();
      break;
    default:
      throw new IllegalStateException("Unknown selectionMode " + selectionMode);
  }

  if (date != null) {
    // Select a new cell.
    if (selectedCells.size() == 0 || !selectedCells.get(0).equals(cell)) {
      selectedCells.add(cell);
      cell.setSelected(true);
    }
    selectedCals.add(newlySelectedCal);

    if (selectionMode == SelectionMode.RANGE && selectedCells.size() > 1) {
      // Select all days in between start and end.
      Date start = selectedCells.get(0).getDate();
      Date end = selectedCells.get(1).getDate();
      selectedCells.get(0).setRangeState(RangeState.FIRST);
      selectedCells.get(1).setRangeState(RangeState.LAST);

      int startMonthIndex = cells.getIndexOfKey(monthKey(selectedCals.get(0)));
      int endMonthIndex = cells.getIndexOfKey(monthKey(selectedCals.get(1)));
      for (int monthIndex = startMonthIndex; monthIndex <= endMonthIndex; monthIndex++) {
        List<List<MonthCellDescriptor>> month = cells.getValueAtIndex(monthIndex);
        for (List<MonthCellDescriptor> week : month) {
          for (MonthCellDescriptor singleCell : week) {
            if (singleCell.getDate().after(start)
                && singleCell.getDate().before(end)
                && singleCell.isSelectable()) {
              if(highlightedCells.contains(singleCell)){
                singleCell.setSelected(false);
                singleCell.setUnavailable(true);
                singleCell.setHighlighted(false);
                selectedCells.add(singleCell);
              }else {
                singleCell.setSelected(true);
                singleCell.setRangeState(RangeState.MIDDLE);
                selectedCells.add(singleCell);
              }

            }
          }
        }
      }
    }
  }

  // Update the adapter.
  validateAndUpdate();
  return date != null;
}
 
开发者ID:savvisingh,项目名称:DateRangePickerLibrary,代码行数:80,代码来源:CalendarPickerView.java


注:本文中的java.util.Calendar.before方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。