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


Java Calendar.compareTo方法代码示例

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


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

示例1: setDate

import java.util.Calendar; //导入方法依赖的package包/类
private void setDate(Calendar date)
{
    setTitleDate(date.getTime());

    int year = date.get(Calendar.YEAR);
    int month = date.get(Calendar.MONTH);
    int day = date.get(Calendar.DATE);

    Calendar calendar = GregorianCalendar.getInstance();
    Calendar today = new GregorianCalendar(calendar.get(Calendar.YEAR),
                                           calendar.get(Calendar.MONTH),
                                           calendar.get(Calendar.DATE));

    prevEntry = getPrevEntry(year, month, day);
    if ((prevEntry == null || today.compareTo(prevEntry) > 0) &&
            today.compareTo(date) < 0)
        prevEntry = today;
    currEntry = date;
    nextEntry = getNextEntry(year, month, day);
    if ((nextEntry == null || today.compareTo(nextEntry) < 0) &&
            today.compareTo(date) > 0)
        nextEntry = today;

    invalidateOptionsMenu();
}
 
开发者ID:billthefarmer,项目名称:diary,代码行数:26,代码来源:Diary.java

示例2: countDutyday

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 计算两个Date之间的工作日时间差
 *
 * @param start 开始时间
 * @param end   结束时间
 * @return int 返回两天之间的工作日时间
 */
public static int countDutyday(Date start, Date end) {
    if (start == null || end == null) return 0;
    if (start.after(end)) return 0;
    Calendar c_start = Calendar.getInstance();
    Calendar c_end = Calendar.getInstance();
    c_start.setTime(start);
    c_end.setTime(end);
    //时分秒毫秒清零
    c_start.set(Calendar.HOUR_OF_DAY, 0);
    c_start.set(Calendar.MINUTE, 0);
    c_start.set(Calendar.SECOND, 0);
    c_start.set(Calendar.MILLISECOND, 0);
    c_end.set(Calendar.HOUR_OF_DAY, 0);
    c_end.set(Calendar.MINUTE, 0);
    c_end.set(Calendar.SECOND, 0);
    c_end.set(Calendar.MILLISECOND, 0);
    //初始化第二个日期,这里的天数可以随便的设置
    int dutyDay = 0;
    while (c_start.compareTo(c_end) < 0) {
        if (c_start.get(Calendar.DAY_OF_WEEK) != 1 && c_start.get(Calendar.DAY_OF_WEEK) != 7)
            dutyDay++;
        c_start.add(Calendar.DAY_OF_YEAR, 1);
    }
    return dutyDay;
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:33,代码来源:DateUtils.java

示例3: start

import java.util.Calendar; //导入方法依赖的package包/类
public static void start(Context ctx) {
    AlarmManager manager = (AlarmManager) ctx.getSystemService("alarm");
    PendingIntent pending = PendingIntent.getBroadcast(ctx, 152, new Intent(ctx,
            SportRemindReceiver.class), 134217728);
    Helper.showLog(TAG, "SportRemindReceiver start");
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();
    calSet.setTimeInMillis(System.currentTimeMillis());
    int remindHour = 20;
    int remindMinute = 30;
    if (!TextUtil.isEmpty(OnePreference.getPrefSportRemindTime())) {
        String[] times = OnePreference.getPrefSportRemindTime().split("#");
        if (times.length == 2) {
            remindHour = Integer.parseInt(times[0]);
            remindMinute = Integer.parseInt(times[1]);
        }
    }
    calSet.set(11, remindHour);
    calSet.set(12, remindMinute);
    calSet.set(13, 0);
    calSet.set(14, 0);
    if (calSet.compareTo(calNow) <= 0) {
        calSet.add(5, 1);
    }
    manager.setRepeating(0, calSet.getTimeInMillis(), a.h, pending);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:27,代码来源:SportRemindReceiver.java

示例4: compareDateOfSecond

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 比较两个日期大小(比较年月日时分秒),com1大于com2返回1,反之返回-1,相等则返回0
 *
 * @param date1
 * @param date2
 * @return
 */
public static int compareDateOfSecond(Date date1, Date date2) {
    Calendar c1 = Calendar.getInstance();
    c1.setTime(date1);
    c1.set(Calendar.MILLISECOND, 0);
    Calendar c2 = Calendar.getInstance();
    c2.setTime(date2);
    c2.set(Calendar.MILLISECOND, 0);
    return c1.compareTo(c2);

}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:18,代码来源:DateUtils.java

示例5: getYearBy

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 获取年份时间段内的所有年
 * 
 * @param StartDate
 * @param endDate
 * @return
 */
public static List<String> getYearBy(String StartDate, String endDate) {
	DateFormat df = new SimpleDateFormat("yyyy");
	Date date1 = null; // 开始日期
	Date date2 = null; // 结束日期
	try {
		date1 = df.parse(StartDate);
		date2 = df.parse(endDate);
	} catch (ParseException e) {
		e.printStackTrace();
	}
	Calendar c1 = Calendar.getInstance();
	Calendar c2 = Calendar.getInstance();
	// 定义集合存放月份
	List<String> list = new ArrayList<String>();
	// 添加第一个月,即开始时间
	list.add(df.format(date1));
	c1.setTime(date1);
	c2.setTime(date2);
	while (c1.compareTo(c2) < 0) {
		c1.add(Calendar.YEAR, 1);// 开始日期加一个月直到等于结束日期为止
		Date ss = c1.getTime();
		String str = df.format(ss);
		list.add(str);
	}
	return list;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:34,代码来源:DateUtils.java

示例6: compareDate

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 根据单位字段比较两个日期
 * 
 * @param date
 *            日期1
 * @param otherDate
 *            日期2
 * @param withUnit
 *            单位字段,从Calendar field取值
 * @return 等于返回0值, 大于返回大于0的值 小于返回小于0的值
 */
public static int compareDate(Date date, Date otherDate, int withUnit) {
	Calendar dateCal = Calendar.getInstance();
	dateCal.setTime(date);
	Calendar otherDateCal = Calendar.getInstance();
	otherDateCal.setTime(otherDate);

	switch (withUnit) {
	case Calendar.YEAR:
		dateCal.clear(Calendar.MONTH);
		otherDateCal.clear(Calendar.MONTH);
	case Calendar.MONTH:
		dateCal.set(Calendar.DATE, 1);
		otherDateCal.set(Calendar.DATE, 1);
	case Calendar.DATE:
		dateCal.set(Calendar.HOUR_OF_DAY, 0);
		otherDateCal.set(Calendar.HOUR_OF_DAY, 0);
	case Calendar.HOUR:
		dateCal.clear(Calendar.MINUTE);
		otherDateCal.clear(Calendar.MINUTE);
	case Calendar.MINUTE:
		dateCal.clear(Calendar.SECOND);
		otherDateCal.clear(Calendar.SECOND);
	case Calendar.SECOND:
		dateCal.clear(Calendar.MILLISECOND);
		otherDateCal.clear(Calendar.MILLISECOND);
	case Calendar.MILLISECOND:
		break;
	default:
		throw new IllegalArgumentException("withUnit 单位字段 " + withUnit + " 不合法!!");
	}
	return dateCal.compareTo(otherDateCal);
}
 
开发者ID:xubinux,项目名称:xbin-store,代码行数:44,代码来源:DateUtils.java

示例7: compareTime

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 根据单位字段比较两个时间
 * 
 * @param date
 *            时间1
 * @param otherDate
 *            时间2
 * @param withUnit
 *            单位字段,从Calendar field取值
 * @return 等于返回0值, 大于返回大于0的值 小于返回小于0的值
 */
public static int compareTime(Date date, Date otherDate, int withUnit) {
	Calendar dateCal = Calendar.getInstance();
	dateCal.setTime(date);
	Calendar otherDateCal = Calendar.getInstance();
	otherDateCal.setTime(otherDate);

	dateCal.clear(Calendar.YEAR);
	dateCal.clear(Calendar.MONTH);
	dateCal.set(Calendar.DATE, 1);
	otherDateCal.clear(Calendar.YEAR);
	otherDateCal.clear(Calendar.MONTH);
	otherDateCal.set(Calendar.DATE, 1);
	switch (withUnit) {
	case Calendar.HOUR:
		dateCal.clear(Calendar.MINUTE);
		otherDateCal.clear(Calendar.MINUTE);
	case Calendar.MINUTE:
		dateCal.clear(Calendar.SECOND);
		otherDateCal.clear(Calendar.SECOND);
	case Calendar.SECOND:
		dateCal.clear(Calendar.MILLISECOND);
		otherDateCal.clear(Calendar.MILLISECOND);
	case Calendar.MILLISECOND:
		break;
	default:
		throw new IllegalArgumentException("withUnit 单位字段 " + withUnit + " 不合法!!");
	}
	return dateCal.compareTo(otherDateCal);
}
 
开发者ID:xubinux,项目名称:xbin-store,代码行数:41,代码来源:DateUtils.java

示例8: applyOutages

import java.util.Calendar; //导入方法依赖的package包/类
private static AppliedOutages applyOutages(Calendar outageDate, int model, boolean logDetail) {
	AppliedOutages result = new AppliedOutages();
	result.setEffectiveStart(outageDate);
	
	// apply outages to model
	log.trace("Apply outages for " + formatter.format(outageDate.getTime()));
	// keep the list of applied outages for later evaluation
	for (Outage outage : outages) {
		result.incramentExaminedOutages();
		if (outage.getEffectiveStartHour().toGregorianCalendar().compareTo(outageDate) <= 0 && outageDate.compareTo(outage.getEffectiveEndHour().toGregorianCalendar()) <= 0) {
			result.incramentOutagesInDateRange();
			OutageModel.OutageMatch outageMatch = OutageModel.match(outage, model, logDetail);
			if (OutageModel.applyOutage(outage, outageMatch, logDetail)) {
				result.getAppliedOutages().add(outage);
				if (result.getEffectiveEnd() == null || result.getEffectiveEnd().compareTo(outage.getEffectiveEndHour().toGregorianCalendar()) > 0) result.setEffectiveEnd((GregorianCalendar)outage.getEffectiveEndHour().toGregorianCalendar().clone());
				result.incramentOutagesApplied();
			} else {
				result.incramentOutagesNotApplied();
			}
		}
	}
	log.trace("Examined " + result.getExaminedOutages() + " outage(s)");
	log.trace("" + result.getOutagesInDateRange() + " outage(s) in date range");
	log.trace("Applied " + result.getOutagesApplied() + " outage(s) in date range");
	log.trace("Did not apply " + result.getOutagesNotApplied() + " outage(s) in date range");

	return result;
}
 
开发者ID:OmniPrise,项目名称:cim-processor,代码行数:29,代码来源:ModelParser.java

示例9: searchNormalEarliestAppointment

import java.util.Calendar; //导入方法依赖的package包/类
private boolean searchNormalEarliestAppointment(List<AvailableAppointment> availableAppointmentList) {
    AvailableAppointment earliestAvappt = null;
    Calendar minCalendar = null;
    for(AvailableAppointment avappt : availableAppointmentList) {
        Entry<Calendar, Map<Integer, List<Time>>> earliestYearMonthEntry = avappt.timeMap.entrySet().iterator().next();
        Calendar earliestYearMonth = earliestYearMonthEntry.getKey();
        if(!earliestYearMonthEntry.getValue().entrySet().isEmpty()) {
            Entry<Integer, List<Time>> earliestDateEntry = earliestYearMonthEntry.getValue().entrySet().iterator().next();
            int earliestDate = earliestDateEntry.getKey();
            if(!earliestDateEntry.getValue().isEmpty()) {
                Time earliestTime = earliestDateEntry.getValue().get(0);
                Calendar cal = Calendar.getInstance();
                cal.set(earliestYearMonth.get(Calendar.YEAR), earliestYearMonth.get(Calendar.MONTH), earliestDate,
                        earliestTime.getHour(), earliestTime.getMinute());
                
                if(minCalendar == null || cal.compareTo(minCalendar) < 0) {
                    minCalendar = cal;
                    earliestAvappt = avappt;
                }
            }
        }
    }
    if(minCalendar != null) {
        saveAsSearchResult(minCalendar, earliestAvappt.testCenter);
        return true;
    } else {
        return false;
    }
}
 
开发者ID:hulang1024,项目名称:PTEAssistant,代码行数:30,代码来源:AppointmentSearcher.java

示例10: searchRangeEarliestAppointment

import java.util.Calendar; //导入方法依赖的package包/类
private boolean searchRangeEarliestAppointment(List<AvailableAppointment> availableAppointmentList) {
    AvailableAppointment earliestAvappt = null;
    Calendar minCalendar = null;
    Time minTime = new Time(startCalendar.get(Calendar.HOUR_OF_DAY), startCalendar.get(Calendar.MINUTE));
    Time maxTime = new Time(endCalendar.get(Calendar.HOUR_OF_DAY), endCalendar.get(Calendar.MINUTE));
    for(AvailableAppointment avappt : availableAppointmentList) {
        Entry<Calendar, Map<Integer, List<Time>>> earliestYearMonthEntry = avappt.timeMap.entrySet().iterator().next();
        Calendar earliestYearMonth = earliestYearMonthEntry.getKey();
        if(!earliestYearMonthEntry.getValue().entrySet().isEmpty()) {
            Entry<Integer, List<Time>> earliestDateEntry = earliestYearMonthEntry.getValue().entrySet().iterator().next();
            int earliestDate = earliestDateEntry.getKey();
            if(!earliestDateEntry.getValue().isEmpty()) {
                Time earliestTime = null;
                for(Time time : earliestDateEntry.getValue()) {
                    if(minTime.compareTo(time)<1 && time.compareTo(maxTime)<1) {
                        earliestTime = time;
                        break;
                    }
                }
                if(earliestTime != null) {
                    Calendar cal = Calendar.getInstance();
                    cal.set(earliestYearMonth.get(Calendar.YEAR), earliestYearMonth.get(Calendar.MONTH), earliestDate,
                            earliestTime.getHour(), earliestTime.getMinute());
                    if(minCalendar == null || cal.compareTo(minCalendar) < 0) {
                        minCalendar = cal;
                        earliestAvappt = avappt;
                    }
                }
            }
        }
    }
    if(minCalendar != null) {
        saveAsSearchResult(minCalendar, earliestAvappt.testCenter);
        return true;
    } else {
        return false;
    }
}
 
开发者ID:hulang1024,项目名称:PTEAssistant,代码行数:39,代码来源:AppointmentSearcher.java

示例11: getRepeatingReminderNextCalendar

import java.util.Calendar; //导入方法依赖的package包/类
public static Calendar getRepeatingReminderNextCalendar(RepeatingReminder repeatingReminder) {

        Calendar today = Calendar.getInstance();
        Calendar endDate = getRepeatingReminderEndCalendar(repeatingReminder);
        Calendar cal = CalendarUtil.getCalendarFromDateAndTime( repeatingReminder.getDate(), repeatingReminder.getTime());

        //TODO: Cant use getDateFieldFromRepeatType(), Gives off a weird warning
        //final int dateField = getDateFieldFromRepeatType(repeatingReminder.getRepeatType());


        while(true) {
            if (cal.compareTo(endDate) >= 0)    //If cal passed endDate, reminder is overdue, return null
                return null;
            if(cal.compareTo(today) >= 0) {
                return cal;
            }

            //TODO: Cant use getDateFieldFromRepeatType(), Gives off a weird warning
            //cal.add(dateField, repeatingReminder.getRepeatInterval()); break;
            switch (repeatingReminder.getRepeatType()) {
                case DAILY: cal.add(Calendar.DAY_OF_WEEK, repeatingReminder.getRepeatInterval()); break;
                case WEEKLY: cal.add(Calendar.WEEK_OF_YEAR, repeatingReminder.getRepeatInterval()); break;
                case MONTHLY: cal.add(Calendar.MONTH, repeatingReminder.getRepeatInterval()); break;
                case YEARLY: cal.add(Calendar.YEAR, repeatingReminder.getRepeatInterval()); break;
                default: throw new InvalidParameterException("Invalid RepeatType parameter in TaskUtil.getRepeatingReminderEndCalendar()");
            }
        }
    }
 
开发者ID:abicelis,项目名称:Remindy,代码行数:29,代码来源:TaskUtil.java

示例12: expiryDateCustomSelected

import java.util.Calendar; //导入方法依赖的package包/类
private void expiryDateCustomSelected() {
    final Calendar today = Calendar.getInstance();
    final Calendar yesterday = Calendar.getInstance();
    yesterday.add(Calendar.DAY_OF_YEAR, -1);
    final Calendar calendar = Calendar.getInstance();
    int currentDay = calendar.get(Calendar.DAY_OF_MONTH);
    int currentMonth = calendar.get(Calendar.MONTH);
    int currentYear = calendar.get(Calendar.YEAR);
    DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(),
            new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                    clearExpiryDateString();
                    calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
                    calendar.set(Calendar.MONTH, datePicker.getMonth());
                    calendar.set(Calendar.YEAR, datePicker.getYear());
                    mExpiryDate = calendar;
                    if (calendar.compareTo(today) == 0) {
                        mExpiryDateSpinner.setSelection(
                                mExpiryDateAdapter.getPosition(
                                        getString(R.string.edit_date_today)));
                    } else if (calendar.compareTo(yesterday) == 0) {
                        mExpiryDateSpinner.setSelection(
                                mExpiryDateAdapter.getPosition(
                                        getString(R.string.edit_date_yesterday)));
                    } else {
                        mExpiryDateString = getSimpleDateFormat().format(calendar.getTime());
                        mExpiryDateAdapter.insert(mExpiryDateString, 0);
                        mExpiryDateSpinner.setSelection(0);
                    }
                    if (mExpiryDateListener) {
                        mPresenter.itemChanged();
                    }
                }
            }, currentYear, currentMonth, currentDay);
    datePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
            mExpiryDateSpinner.setSelection(mPreviousExpiryDateOption);
        }
    });
    datePickerDialog.show();
}
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:44,代码来源:EditItemFragment.java

示例13: getViewAt

import java.util.Calendar; //导入方法依赖的package包/类
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
    if (position < mItems.size()) {
        String category = mItems.get(position).getCategory();
        if (category == null || category.equals("")) {
            rv.setTextViewText(R.id.category, getString(R.string.edit_category_empty));
        } else {
            rv.setTextViewText(R.id.category, category);
        }
        String type = mItems.get(position).getType();
        if (type == null || type.equals("")) {
            rv.setTextViewText(R.id.type, getString(R.string.edit_type_empty));
        } else {
            rv.setTextViewText(R.id.type, type);
        }
        String colour = mItems.get(position).getMainColour();
        if (colour == null || colour.equals("")) {
            rv.setTextViewText(R.id.colour, getString(R.string.edit_main_colour_empty));
        } else {
            rv.setTextViewText(R.id.colour, colour);
        }
        long expiry = mItems.get(position).getExpiry();
        if (expiry == -1) {
            setTextColourPrimary(rv);
            rv.setTextViewText(R.id.expiry, getString(R.string.edit_expiry_date_empty));
        } else {
            Calendar expiryDate = Calendar.getInstance();
            expiryDate.setTimeInMillis(expiry);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(getString(
                    R.string.edit_date_format),
                    Locale.ENGLISH);
            String expiryString = simpleDateFormat.format(expiryDate.getTime());
            rv.setTextViewText(R.id.expiry, expiryString);
            Calendar almostExpiredDate = Calendar.getInstance();
            almostExpiredDate.add(Calendar.MONTH, 1);
            if (expiryDate.compareTo(Calendar.getInstance()) < 1) {
                rv.setInt(R.id.expiry, "setTextColor", ContextCompat.getColor(mContext,
                        R.color.red));
            } else if (expiryDate.compareTo(almostExpiredDate) < 1) {
                rv.setInt(R.id.expiry, "setTextColor", ContextCompat.getColor(mContext,
                        R.color.orange));
            } else {
                setTextColourPrimary(rv);
            }
        }
        int price = mItems.get(position).getPricePaid();
        String priceString;
        if (price == -1) {
            priceString = getString(R.string.edit_price_paid_empty);
        } else {
            priceString = getString(R.string.edit_price_paid_prefix)
                    + getPriceFromTotalCents(price);
        }
        rv.setTextViewText(R.id.paid, priceString);

        Intent fillInIntent = new Intent();
        fillInIntent.putExtra(EXTRA_ITEM_ID, mItems.get(position).getId());
        rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent);
    }
    return rv;
}
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:63,代码来源:WidgetListService.java

示例14: onBindViewHolder

import java.util.Calendar; //导入方法依赖的package包/类
@Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            if (mLargeScreen) {
                String imageUrl = mItems.get(position).getImageUrl();
                if (imageUrl != null) {
                    if (!imageUrl.equals(mImageUrl)) {
                        mImageUrl = imageUrl;
                    }
                    holder.mItemImage.setVisibility(View.VISIBLE);
//                    EspressoIdlingResource.increment();
                    Glide.with(getContext())
                            .load(imageUrl)
                            .crossFade()
                            .centerCrop()
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .into(new GlideDrawableImageViewTarget(holder.mItemImage) {
                                @Override
                                public void onResourceReady(GlideDrawable resource,
                                                            GlideAnimation<? super GlideDrawable> animation) {
                                    super.onResourceReady(resource, animation);
//                                    EspressoIdlingResource.decrement();
                                }
                            });

                } else {
                    holder.mItemImage.setVisibility(View.GONE);
                }
            }
            String category = mItems.get(position).getCategory();
            if (category == null || category.equals("")) {
                holder.mCategory.setText(getString(R.string.edit_category_empty));
            } else {
                holder.mCategory.setText(category);
            }
            String type = mItems.get(position).getType();
            if (type == null || type.equals("")) {
                holder.mType.setText(getString(R.string.edit_type_empty));
            } else {
                holder.mType.setText(mItems.get(position).getType());
            }
            String colour = mItems.get(position).getMainColour();
            if (colour == null || colour.equals("")) {
                holder.mColour.setText(getString(R.string.edit_main_colour_empty));
            } else {
                holder.mColour.setText(mItems.get(position).getMainColour());
            }
            long expiry = mItems.get(position).getExpiry();
            if (expiry == -1) {
                setTextColourPrimary(holder);
                holder.mExpiry.setText(getString(R.string.edit_expiry_date_empty));
            } else {
                Calendar expiryDate = Calendar.getInstance();
                expiryDate.setTimeInMillis(expiry);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(getString(
                        R.string.edit_date_format), Locale.ENGLISH);
                String expiryString = simpleDateFormat.format(expiryDate.getTime());
                holder.mExpiry.setText(expiryString);
                Calendar almostExpiredDate = Calendar.getInstance();
                almostExpiredDate.add(Calendar.MONTH, 1);
                if (expiryDate.compareTo(Calendar.getInstance()) < 1) {
                    holder.mExpiry.setTextColor(ContextCompat.getColor(getContext(), R.color.red));
                } else if (expiryDate.compareTo(almostExpiredDate) < 1) {
                    holder.mExpiry.setTextColor(ContextCompat.getColor(getContext(), R.color.orange));
                } else {
                    setTextColourPrimary(holder);
                }
            }
            int price = mItems.get(position).getPricePaid();
            String priceString;
            if (price == -1) {
                priceString = getString(R.string.edit_price_paid_empty);
            } else {
                priceString = getString(R.string.edit_price_paid_prefix)
                        + getPriceFromTotalCents(price);
            }
            holder.mPaid.setText(priceString);
        }
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:78,代码来源:ItemsFragment.java

示例15: purchaseDateCustomSelected

import java.util.Calendar; //导入方法依赖的package包/类
private void purchaseDateCustomSelected() {
    final Calendar today = Calendar.getInstance();
    final Calendar yesterday = Calendar.getInstance();
    yesterday.add(Calendar.DAY_OF_YEAR, -1);
    final Calendar calendar = Calendar.getInstance();
    int currentDay = calendar.get(Calendar.DAY_OF_MONTH);
    int currentMonth = calendar.get(Calendar.MONTH);
    int currentYear = calendar.get(Calendar.YEAR);
    DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(),
            new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                    clearPurchaseDateString();
                    calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
                    calendar.set(Calendar.MONTH, datePicker.getMonth());
                    calendar.set(Calendar.YEAR, datePicker.getYear());
                    mPurchaseDate = calendar;
                    if (calendar.compareTo(today) == 0) {
                        mPurchaseDateSpinner.setSelection(
                                mPurchaseDateAdapter.getPosition(
                                        getString(R.string.edit_date_today)));
                    } else if (calendar.compareTo(yesterday) == 0) {
                        mPurchaseDateSpinner.setSelection(
                                mPurchaseDateAdapter.getPosition(
                                        getString(R.string.edit_date_yesterday)));
                    } else {
                        mPurchaseDateString = getSimpleDateFormat().format(calendar.getTime());
                        mPurchaseDateAdapter.insert(mPurchaseDateString, 0);
                        mPurchaseDateSpinner.setSelection(0);
                    }
                    if (mPurchaseDateListener) {
                        mPresenter.itemChanged();
                    }
                }
            }, currentYear, currentMonth, currentDay);
    datePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
            mPurchaseDateSpinner.setSelection(mPreviousPurchaseDateOption);
        }
    });
    datePickerDialog.show();
}
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:44,代码来源:EditItemFragment.java


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