Java Code Examples for java.util.Calendar.before()

The following are Jave code examples for showing how to use before() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Material-Calendar-View   File: CalendarView.java   View Source Code Vote up 7 votes
/**
 * 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();
}
 
Example 2
Project: oscm   File: CostCalculatorPerUnit.java   View Source Code Vote up 7 votes
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;
    }
}
 
Example 3
Project: lams   File: CalendarComparator.java   View Source Code Vote up 6 votes
public int compare(Calendar x, Calendar y) {
	if ( x.before( y ) ) {
		return -1;
	}
	if ( x.after( y ) ) {
		return 1;
	}
	return 0;
}
 
Example 4
Project: PosTrainer   File: AlarmService.java   View Source Code Vote up 6 votes
private void checkAlarm(Calendar alarm) {
    Calendar now = Calendar.getInstance();
    if (alarm.before(now)) {
        long alarmForFollowingDay = alarm.getTimeInMillis() + 86400000L;
        alarm.setTimeInMillis(alarmForFollowingDay);
    }
}
 
Example 5
Project: NeverLag   File: DateUtils.java   View Source Code Vote up 6 votes
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;
}
 
Example 6
Project: My-Blog   File: DateKit.java   View Source Code Vote up 6 votes
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;
        }
    }
}
 
Example 7
Project: kfaryarok-android   File: AlertHelper.java   View Source Code Vote up 6 votes
/**
 * 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);
}
 
Example 8
Project: JRediClients   File: TimeUtils.java   View Source Code Vote up 6 votes
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;
	}
}
 
Example 9
Project: chromium-for-android-56-debug-video   File: DateDividedAdapter.java   View Source Code Vote up 6 votes
/**
 * @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;
    }
}
 
Example 10
Project: openjdk-jdk10   File: CalendarRegression.java   View Source Code Vote up 6 votes
/**
 * 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.");
    }
}
 
Example 11
Project: calendarview2   File: Range.java   View Source Code Vote up 6 votes
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;
}
 
Example 12
Project: FakeWeather   File: TimeUtils.java   View Source Code Vote up 6 votes
/**
 * 判断当前时间是否在两个时间段之内
 *
 * @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;
    }
}
 
Example 13
Project: Material-Calendar-View   File: DayRowClickListener.java   View Source Code Vote up 5 votes
private boolean isBetweenMinAndMax(Calendar day) {
    return !((mCalendarProperties.getMinimumDate() != null && day.before(mCalendarProperties.getMinimumDate()))
            || (mCalendarProperties.getMaximumDate() != null && day.after(mCalendarProperties.getMaximumDate())));
}
 
Example 14
Project: buildAPKsApps   File: AlarmNotificationService.java   View Source Code Vote up 5 votes
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);
}
 
Example 15
Project: DateRangePickerLibrary   File: CalendarPickerView.java   View Source Code Vote up 5 votes
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;
}
 
Example 16
Project: screenfilter   File: Utility.java   View Source Code Vote up 5 votes
public static void updateAlarmSettings(Context context) {
    AppSetting settings = AppSetting.newInstance(context);
    if (settings.getBoolean(AppSetting.KEY_AUTO_MODE, false)) {
        int hrsSunrise = settings.getInt(AppSetting.KEY_HOURS_STOP, 6);
        int minSunrise = settings.getInt(AppSetting.KEY_MINUTES_STOP, 0);
        int hrsSunset = settings.getInt(AppSetting.KEY_HOURS_START, 22);
        int minSunset = settings.getInt(AppSetting.KEY_MINUTES_START, 0);

        Calendar now = Calendar.getInstance();
        Calendar sunriseCalendar = (Calendar) now.clone();
        Calendar sunsetCalendar = (Calendar) now.clone();

        sunriseCalendar.set(Calendar.HOUR_OF_DAY, hrsSunrise);
        sunriseCalendar.set(Calendar.MINUTE, minSunrise);
        sunriseCalendar.set(Calendar.SECOND, 0);
        sunriseCalendar.set(Calendar.MILLISECOND, 0);
        if (sunriseCalendar.before(now)) sunriseCalendar.add(Calendar.DATE, 1);

        sunsetCalendar.set(Calendar.HOUR_OF_DAY, hrsSunset);
        sunsetCalendar.set(Calendar.MINUTE, minSunset);
        sunsetCalendar.set(Calendar.SECOND, 0);
        sunsetCalendar.set(Calendar.MILLISECOND, 0);
        if (sunsetCalendar.before(now)) sunsetCalendar.add(Calendar.DATE, 1);

        Log.i(TAG, "Reset alarm");

        cancelAlarm(context, REQUEST_ALARM_SUNRISE, Constants.ALARM_ACTION_STOP);
        cancelAlarm(context, REQUEST_ALARM_SUNSET, Constants.ALARM_ACTION_START);
        setAlarm(context,
                AlarmManager.RTC_WAKEUP,
                sunriseCalendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY,
                REQUEST_ALARM_SUNRISE,
                Constants.ALARM_ACTION_STOP);
        setAlarm(context,
                AlarmManager.RTC_WAKEUP,
                sunsetCalendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY,
                REQUEST_ALARM_SUNSET,
                Constants.ALARM_ACTION_START);
    } else {
        Log.i(TAG, "Cancel alarm");
        cancelAlarm(context, REQUEST_ALARM_SUNRISE, Constants.ALARM_ACTION_STOP);
        cancelAlarm(context, REQUEST_ALARM_SUNSET, Constants.ALARM_ACTION_START);
    }
}
 
Example 17
Project: lams   File: DailyCalendar.java   View Source Code Vote up 5 votes
/**
 * Sets the time range for the <CODE>DailyCalendar</CODE> to the times
 * represented in the specified values.  
 * 
 * @param rangeStartingHourOfDay the hour of the start of the time range
 * @param rangeStartingMinute    the minute of the start of the time range
 * @param rangeStartingSecond    the second of the start of the time range
 * @param rangeStartingMillis    the millisecond of the start of the time
 *                               range
 * @param rangeEndingHourOfDay   the hour of the end of the time range
 * @param rangeEndingMinute      the minute of the end of the time range
 * @param rangeEndingSecond      the second of the end of the time range
 * @param rangeEndingMillis      the millisecond of the start of the time 
 *                               range
 */
public void setTimeRange(int rangeStartingHourOfDay,
                          int rangeStartingMinute,
                          int rangeStartingSecond,
                          int rangeStartingMillis,
                          int rangeEndingHourOfDay,
                          int rangeEndingMinute,
                          int rangeEndingSecond,
                          int rangeEndingMillis) {
    validate(rangeStartingHourOfDay,
             rangeStartingMinute,
             rangeStartingSecond,
             rangeStartingMillis);
    
    validate(rangeEndingHourOfDay,
             rangeEndingMinute,
             rangeEndingSecond,
             rangeEndingMillis);
    
    Calendar startCal = createJavaCalendar();
    startCal.set(Calendar.HOUR_OF_DAY, rangeStartingHourOfDay);
    startCal.set(Calendar.MINUTE, rangeStartingMinute);
    startCal.set(Calendar.SECOND, rangeStartingSecond);
    startCal.set(Calendar.MILLISECOND, rangeStartingMillis);
    
    Calendar endCal = createJavaCalendar();
    endCal.set(Calendar.HOUR_OF_DAY, rangeEndingHourOfDay);
    endCal.set(Calendar.MINUTE, rangeEndingMinute);
    endCal.set(Calendar.SECOND, rangeEndingSecond);
    endCal.set(Calendar.MILLISECOND, rangeEndingMillis);
    
    if (!startCal.before(endCal)) {
        throw new IllegalArgumentException(invalidTimeRange +
                rangeStartingHourOfDay + ":" +
                rangeStartingMinute + ":" +
                rangeStartingSecond + ":" +
                rangeStartingMillis + separator +
                rangeEndingHourOfDay + ":" +
                rangeEndingMinute + ":" +
                rangeEndingSecond + ":" +
                rangeEndingMillis);
    }
    
    this.rangeStartingHourOfDay = rangeStartingHourOfDay;
    this.rangeStartingMinute = rangeStartingMinute;
    this.rangeStartingSecond = rangeStartingSecond;
    this.rangeStartingMillis = rangeStartingMillis;
    this.rangeEndingHourOfDay = rangeEndingHourOfDay;
    this.rangeEndingMinute = rangeEndingMinute;
    this.rangeEndingSecond = rangeEndingSecond;
    this.rangeEndingMillis = rangeEndingMillis;
}
 
Example 18
Project: Open-DM   File: LoadSchedule.java   View Source Code Vote up 5 votes
public boolean inLowLoadTimeWindow(Calendar currentTime) {
    if (!isLowLoadEnabled()) {
        return false;
    }

    // Use calendar objects. Set them at the current time and then get the hours and minutes
    // from the load
    // schedule and adjust them for those values
    Calendar startTime = (Calendar) currentTime.clone();
    Calendar endTime = (Calendar) currentTime.clone();
    boolean reverse = getLowLoadEndTime().before(getLowLoadStartTime());

    Calendar cal = Calendar.getInstance();
    cal.setTime(getLowLoadStartTime());
    int startLowLoadHour = cal.get(Calendar.HOUR_OF_DAY);
    int startLowLoadMin = cal.get(Calendar.MINUTE);

    cal.setTime(getLowLoadEndTime());
    int endLowLoadHour = cal.get(Calendar.HOUR_OF_DAY);
    int endLowLoadMin = cal.get(Calendar.MINUTE);

    startTime.set(Calendar.HOUR_OF_DAY, startLowLoadHour);
    startTime.set(Calendar.MINUTE, startLowLoadMin);
    startTime.set(Calendar.SECOND, 0);
    endTime.set(Calendar.HOUR_OF_DAY, endLowLoadHour);
    endTime.set(Calendar.MINUTE, endLowLoadMin);
    endTime.set(Calendar.SECOND, 0);

    // If we are in a reverse period (ex 20 - 02) we have to adjust the start and end times by a
    // day. If end time
    // is before the current time (ex 23) the we move the end time up a day. Else move the start
    // time back a day.
    if (reverse) {
        if (endTime.before(currentTime)) {
            endTime.add(Calendar.DATE, 1);
        } else {
            startTime.add(Calendar.DATE, -1);
        }
    }

    boolean within = currentTime.after(startTime) && currentTime.before(endTime);
    return within;
}
 
Example 19
Project: HiBangClient   File: MyDateUtils.java   View Source Code Vote up 5 votes
/**
	 * 格式化时间
	 * @param time
	 * @return
	 */
	public static String formatDateTime(String time) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		if(time==null ||"".equals(time)){
			return "";
		}
		Date date = null;
		try {
			date = format.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		Calendar current = Calendar.getInstance();
		
		Calendar today = Calendar.getInstance();	//今天
		
		today.set(Calendar.YEAR, current.get(Calendar.YEAR));
		today.set(Calendar.MONTH, current.get(Calendar.MONTH));
		today.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH));
		//  Calendar.HOUR——12小时制的小时数 Calendar.HOUR_OF_DAY——24小时制的小时数
		today.set( Calendar.HOUR_OF_DAY, 0);
		today.set( Calendar.MINUTE, 0);
		today.set(Calendar.SECOND, 0);
		
		Calendar tomorrow = Calendar.getInstance();	//明天
		
		tomorrow.set(Calendar.YEAR, current.get(Calendar.YEAR));
		tomorrow.set(Calendar.MONTH, current.get(Calendar.MONTH));
		tomorrow.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH)+1);
		tomorrow.set( Calendar.HOUR_OF_DAY, 0);
		tomorrow.set( Calendar.MINUTE, 0);
		tomorrow.set(Calendar.SECOND, 0);
		
        Calendar afterTomorrow = Calendar.getInstance();	//后天
		
        afterTomorrow.set(Calendar.YEAR, current.get(Calendar.YEAR));
        afterTomorrow.set(Calendar.MONTH, current.get(Calendar.MONTH));
        afterTomorrow.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH)+2);
        afterTomorrow.set( Calendar.HOUR_OF_DAY, 0);
        afterTomorrow.set( Calendar.MINUTE, 0);
        afterTomorrow.set(Calendar.SECOND, 0);
		
        Calendar bigAfterTomorrow = Calendar.getInstance();	//大后天
		
        bigAfterTomorrow.set(Calendar.YEAR, current.get(Calendar.YEAR));
        bigAfterTomorrow.set(Calendar.MONTH, current.get(Calendar.MONTH));
        bigAfterTomorrow.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH)+3);
        bigAfterTomorrow.set( Calendar.HOUR_OF_DAY, 0);
        bigAfterTomorrow.set( Calendar.MINUTE, 0);
        bigAfterTomorrow.set(Calendar.SECOND, 0);
        
		current.setTime(date);
		
		if(current.after(today) && current.before(tomorrow)){
			return "今天  ";
		}else if(current.before(afterTomorrow) && current.after(tomorrow)){
			return "明天  ";
		}else if(current.before(bigAfterTomorrow) && current.after(afterTomorrow)){
			return "后天  ";
		}else{
//			int index = time.indexOf("-")+1;
//			return time.substring(index, time.length());
			return "";
		}
	}
 
Example 20
Project: GongXianSheng   File: DateFormateUtil.java   View Source Code Vote up 4 votes
/**
 * Description:判断是不是昨天
 * 
 * @param c
 * @return
 * @return boolean
 * @author name:拜力文
 *         <p>=
 *         ===========================================
 *         </p>
 *         Modified No: Modified By: Modified Date: Modified Description:
 *         <p>=
 *         ===========================================
 *         </p>
 **/
public static boolean isYesterday(Calendar c) {
	Calendar today_start = Calendar
			.getInstance(TimeZone.getTimeZone(GMT_8));
	today_start.set(Calendar.HOUR_OF_DAY, 0);
	today_start.set(Calendar.MINUTE, 0);
	today_start.add(Calendar.DAY_OF_MONTH, -1);
	Calendar today_end = Calendar.getInstance(TimeZone.getTimeZone(GMT_8));
	today_end.set(Calendar.HOUR_OF_DAY, 0);
	today_end.set(Calendar.MINUTE, 0);

	return c.before(today_end) && c.after(today_start);
}