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


Java Calendar.DATE属性代码示例

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


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

示例1: getMillisPerUnit

/**
 * Returns the number of millis of a datefield, if this is a constant value
 * 
 * @param unit A Calendar field which is a valid unit for a fragment
 * @return number of millis
 * @throws IllegalArgumentException if date can't be represented in millisenconds
 * @since 2.4 
 */
private static long getMillisPerUnit(int unit) {
    long result = Long.MAX_VALUE;
    switch (unit) {
        case Calendar.DAY_OF_YEAR:
        case Calendar.DATE:
            result = MILLIS_PER_DAY;
            break;
        case Calendar.HOUR_OF_DAY:
            result = MILLIS_PER_HOUR;
            break;
        case Calendar.MINUTE:
            result = MILLIS_PER_MINUTE;
            break;
        case Calendar.SECOND:
            result = MILLIS_PER_SECOND;
            break;
        case Calendar.MILLISECOND:
            result = 1;
            break;
        default: throw new IllegalArgumentException("The unit " + unit + " cannot be represented is milleseconds");
    }
    return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:DateUtils.java

示例2: getCalendarField

/**
 * Returns a field code (that can be used with the Calendar class) for a given 'unit' code.
 * The 'unit' is one of:  YEAR, MONTH, DAY, HOUR, MINUTE, SECOND and MILLISECOND.
 *
 * @param unit  the unit.
 *
 * @return the field code.
 */
private int getCalendarField(int unit) {

    switch (unit) {
        case (YEAR):
            return Calendar.YEAR;
        case (MONTH):
            return Calendar.MONTH;
        case (DAY):
            return Calendar.DATE;
        case (HOUR):
            return Calendar.HOUR_OF_DAY;
        case (MINUTE):
            return Calendar.MINUTE;
        case (SECOND):
            return Calendar.SECOND;
        case (MILLISECOND):
            return Calendar.MILLISECOND;
        default:
            return Calendar.MILLISECOND;
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:DateTickUnit.java

示例3: getCalendarField

/**
 * Returns a field code (that can be used with the Calendar class) for a 
 * given 'unit' code.  The 'unit' is one of:  {@link #YEAR}, {@link #MONTH},
 * {@link #DAY}, {@link #HOUR}, {@link #MINUTE}, {@link #SECOND} and 
 * {@link #MILLISECOND}.
 *
 * @param tickUnit  the unit.
 *
 * @return The field code.
 */
private int getCalendarField(int tickUnit) {

    switch (tickUnit) {
        case (YEAR):
            return Calendar.YEAR;
        case (MONTH):
            return Calendar.MONTH;
        case (DAY):
            return Calendar.DATE;
        case (HOUR):
            return Calendar.HOUR_OF_DAY;
        case (MINUTE):
            return Calendar.MINUTE;
        case (SECOND):
            return Calendar.SECOND;
        case (MILLISECOND):
            return Calendar.MILLISECOND;
        default:
            return Calendar.MILLISECOND;
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:32,代码来源:DateTickUnit.java

示例4: getInterval

/**
 * 获取时间间隔类型
 *
 * @param field
 *            时间间隔类型
 * @return 日历的时间间隔
 */
protected static int getInterval(String field) {
    String tmpField = field.toUpperCase();
    if (DEFAULT_YEAR.equals(tmpField)) {
        return Calendar.YEAR;
    } else if (DEFAULT_MONTH.equals(tmpField)) {
        return Calendar.MONTH;
    } else if (DEFAULT_DATE.equals(tmpField)) {
        return Calendar.DATE;
    } else if (DEFAULT_HOUR.equals(tmpField)) {
        return Calendar.HOUR;
    } else if (DEFAULT_MINUTE.equals(tmpField)) {
        return Calendar.MINUTE;
    } else {
        return Calendar.SECOND;
    }
}
 
开发者ID:PekingGo,项目名称:ipayquery,代码行数:23,代码来源:DateUtil.java

示例5: dateDiff

public static long dateDiff(Date startTime, Date endTime, int type) {
    long result = 0;
    long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
    long nh = 1000 * 60 * 60;// 一小时的毫秒数
    long nm = 1000 * 60;// 一分钟的毫秒数
    long ns = 1000;// 一秒钟的毫秒数
    long diff;
    try {
        // 获得两个时间的毫秒时间差异
        diff = endTime.getTime() - startTime.getTime();
        switch (type) {
            case Calendar.DATE:
                result = diff / nd;// 计算差多少天
                break;
            case Calendar.HOUR:
                result = diff % nd / nh;// 计算差多少小时
                break;
            case Calendar.MINUTE:
                result = diff % nd % nh / nm;// 计算差多少分钟
                break;
            case Calendar.SECOND:
                result = diff % nd % nh % nm / ns;// 计算差多少秒
                break;
            default:
                break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
开发者ID:Wangsu-Cloud-Storage,项目名称:wcs-android-sdk,代码行数:31,代码来源:DateUtil.java

示例6: compareDate

/**
 * 根据单位字段比较两个日期
 * 
 * @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,代码行数:43,代码来源:DateUtils.java

示例7: getTimeRelativeTo

public long getTimeRelativeTo(long time)
{
	int valueToUse = -(int) value;
	int field = 0;
	if (getUnit() == TimeUnit.MILLISECONDS)
	{
		field = Calendar.MILLISECOND;
		//we do our own adjustment as calendar cannot handle a long.
		time -= value;
		valueToUse = 0;
	}
	else if (getUnit() == TimeUnit.SECONDS)
		field = Calendar.SECOND;
	else if (getUnit() == TimeUnit.MINUTES)
		field = Calendar.MINUTE;
	else if (getUnit() == TimeUnit.HOURS)
		field = Calendar.HOUR;
	else if (getUnit() == TimeUnit.DAYS)
		field = Calendar.DATE;
	else if (getUnit() == TimeUnit.WEEKS)
		field = Calendar.WEEK_OF_MONTH;
	else if (getUnit() == TimeUnit.MONTHS)
		field = Calendar.MONTH;
	else if (getUnit() == TimeUnit.YEARS)
		field = Calendar.YEAR;

	calendar.setTimeInMillis(time);
	calendar.add(field, valueToUse);

	return calendar.getTime().getTime();
}
 
开发者ID:quqiangsheng,项目名称:abhot,代码行数:31,代码来源:RelativeTime.java

示例8: getFutureTimeRelativeTo

public long getFutureTimeRelativeTo(long time)
{
	int valueToUse = (int) value;
	int field = 0;
	if (getUnit() == TimeUnit.MILLISECONDS)
	{
		field = Calendar.MILLISECOND;
		//we do our own adjustment as calendar cannot handle a long.
		time += value;
		valueToUse = 0;
	}
	else if (getUnit() == TimeUnit.SECONDS)
		field = Calendar.SECOND;
	else if (getUnit() == TimeUnit.MINUTES)
		field = Calendar.MINUTE;
	else if (getUnit() == TimeUnit.HOURS)
		field = Calendar.HOUR;
	else if (getUnit() == TimeUnit.DAYS)
		field = Calendar.DATE;
	else if (getUnit() == TimeUnit.WEEKS)
		field = Calendar.WEEK_OF_MONTH;
	else if (getUnit() == TimeUnit.MONTHS)
		field = Calendar.MONTH;
	else if (getUnit() == TimeUnit.YEARS)
		field = Calendar.YEAR;

	calendar.setTimeInMillis(time);
	calendar.add(field, valueToUse);

	return calendar.getTime().getTime();
}
 
开发者ID:quqiangsheng,项目名称:abhot,代码行数:31,代码来源:RelativeTime.java

示例9: checkTime

private boolean checkTime(Date date, int kind) {
    Calendar currentCalendar = Calendar.getInstance();
    currentCalendar.setTime(Utils.getAnalyticsDate());

    Calendar orderCalendar = Calendar.getInstance();
    orderCalendar.setTime(date);
    switch (kind) {
        case Calendar.DATE:
            if (orderCalendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR) &&
                    orderCalendar.get(Calendar.MONTH) == currentCalendar.get(Calendar.MONTH) &&
                    orderCalendar.get(Calendar.DATE) == currentCalendar.get(Calendar.DAY_OF_MONTH)) {
                return true;
            }
            break;
        case Calendar.WEEK_OF_YEAR:
            if (orderCalendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR) &&
                    orderCalendar.get(Calendar.WEEK_OF_YEAR) == currentCalendar.get(Calendar.WEEK_OF_YEAR)) {
                return true;
            }
            break;
        case Calendar.MONTH:
            if (orderCalendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR) &&
                    orderCalendar.get(Calendar.MONTH) == currentCalendar.get(Calendar.MONTH)) {
                return true;
            }
            break;
        default:
            return false;
    }
    return false;
}
 
开发者ID:Wisebite,项目名称:wisebite_android,代码行数:31,代码来源:RestaurantService.java

示例10: computeGregorianFields

/**
 * 使用农历日期计算出公历日期
 */
private void computeGregorianFields() {
    int y = lunarYear;
    int m = lunarMonth;
    int d = lunarDate;

    areLunarFieldsComputed = true;
    areFieldsSet = true;
    lastSetLunar = false;

    // 调整日期范围
    if (y < 1900) {
        y = 1899;
    }
    else if (y > 2100) {
        y = 2101;
    }
    
    if (m < -12) {
        m = -12;
    }
    else if (m > 12) {
        m = 12;
    }

    if (d < 1) {
        d = 1;
    }
    else if (d > 30) {
        d = 30;
    }

    int dateInt = y * 10000 + Math.abs(m) * 100 + d;
    if (dateInt < 19001111) {
        // 太小
        set(1901, Calendar.JANUARY, 1);
        super.complete();
    } else if (dateInt > 21001201) {
        // 太大
        set(2100, Calendar.DECEMBER, 31);
        super.complete();
    } else {
        if (Math.abs(m) > 12) {
            m = 12;
        }

        int days = LunarCalendar.daysInLunarMonth(y, m);
        if (days == 0) {
            m = -m;
            days = LunarCalendar.daysInLunarMonth(y, m);
        }

        if (d > days) {
            d = days;
        }

        set(y, Math.abs(m) - 1, d);
        computeLunarFields();

        int amount = 0;
        while (lunarYear != y || lunarMonth != m) {
            amount += daysInLunarMonth(lunarYear, lunarMonth);
            lunarMonth = nextLunarMonth(lunarYear, lunarMonth);
        }

        amount += d - lunarDate;
        super.add(Calendar.DATE, amount);
    }

    computeLunarFields();
}
 
开发者ID:mainh,项目名称:MainCalendar,代码行数:73,代码来源:LunarCalendar.java

示例11: getFragment

/**
 * Calendar-version for fragment-calculation in any unit
 * 
 * @param calendar the calendar to work with, not null
 * @param fragment the Calendar field part of calendar to calculate 
 * @param unit Calendar field defining the unit
 * @return number of units within the fragment of the calendar
 * @throws IllegalArgumentException if the date is <code>null</code> or 
 * fragment is not supported
 * @since 2.4
 */
private static long getFragment(Calendar calendar, int fragment, int unit) {
    if(calendar == null) {
        throw  new IllegalArgumentException("The date must not be null"); 
    }
    long millisPerUnit = getMillisPerUnit(unit);
    long result = 0;
    
    // Fragments bigger than a day require a breakdown to days
    switch (fragment) {
        case Calendar.YEAR:
            result += (calendar.get(Calendar.DAY_OF_YEAR) * MILLIS_PER_DAY) / millisPerUnit;
            break;
        case Calendar.MONTH:
            result += (calendar.get(Calendar.DAY_OF_MONTH) * MILLIS_PER_DAY) / millisPerUnit;
            break;
    }

    switch (fragment) {
        // Number of days already calculated for these cases
        case Calendar.YEAR:
        case Calendar.MONTH:
        
        // The rest of the valid cases
        case Calendar.DAY_OF_YEAR:
        case Calendar.DATE:
            result += (calendar.get(Calendar.HOUR_OF_DAY) * MILLIS_PER_HOUR) / millisPerUnit;
            //$FALL-THROUGH$
        case Calendar.HOUR_OF_DAY:
            result += (calendar.get(Calendar.MINUTE) * MILLIS_PER_MINUTE) / millisPerUnit;
            //$FALL-THROUGH$
        case Calendar.MINUTE:
            result += (calendar.get(Calendar.SECOND) * MILLIS_PER_SECOND) / millisPerUnit;
            //$FALL-THROUGH$
        case Calendar.SECOND:
            result += (calendar.get(Calendar.MILLISECOND) * 1) / millisPerUnit;
            break;
        case Calendar.MILLISECOND: 
            break;//never useful
        default: 
            throw new IllegalArgumentException("The fragment " + fragment + " is not supported");
    }
    return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:54,代码来源:DateUtils.java

示例12: makeDatesEven

/**
 * Makes dates even, in the sense of that years always begin in January,
 * months always begin on the 1st and days always at midnight.
 *
 * @param dates The list of dates.
 * @return The new list of dates.
 */
private List<Date> makeDatesEven(List<Date> dates, Calendar calendar) {
    // If the dates contain more dates than just the lower and upper bounds, make the dates in between even.
    if (dates.size() > 2) {
        List<Date> evenDates = new ArrayList<>();

        // For each interval, modify the date slightly by a few millis, to make sure they are different days.
        // This is because Axis stores each value and won't update the tick labels, if the value is already known.
        // This happens if you display days and then add a date many years in the future the tick label will still be displayed as day.
        for (int i = 0; i < dates.size(); i++) {
            calendar.setTime(dates.get(i));
            switch (actualInterval.interval) {
                case Calendar.YEAR:
                    // If its not the first or last date (lower and upper bound), make the year begin with first month and let the months begin with first day.
                    if (i != 0 && i != dates.size() - 1) {
                        calendar.set(Calendar.MONTH, 0);
                        calendar.set(Calendar.DATE, 1);
                    }
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 6);
                    break;
                case Calendar.MONTH:
                    // If its not the first or last date (lower and upper bound), make the months begin with first day.
                    if (i != 0 && i != dates.size() - 1) {
                        calendar.set(Calendar.DATE, 1);
                    }
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 5);
                    break;
                case Calendar.WEEK_OF_YEAR:
                    // Make weeks begin with first day of week?
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 4);
                    break;
                case Calendar.DATE:
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 3);
                    break;
                case Calendar.HOUR:
                    if (i != 0 && i != dates.size() - 1) {
                        calendar.set(Calendar.MINUTE, 0);
                        calendar.set(Calendar.SECOND, 0);
                    }
                    calendar.set(Calendar.MILLISECOND, 2);
                    break;
                case Calendar.MINUTE:
                    if (i != 0 && i != dates.size() - 1) {
                        calendar.set(Calendar.SECOND, 0);
                    }
                    calendar.set(Calendar.MILLISECOND, 1);
                    break;
                case Calendar.SECOND:
                    calendar.set(Calendar.MILLISECOND, 0);
                    break;

            }
            evenDates.add(calendar.getTime());
        }

        return evenDates;
    } else {
        return dates;
    }
}
 
开发者ID:dainesch,项目名称:HueSense,代码行数:78,代码来源:DateAxis.java

示例13: setArrivalTime

public void setArrivalTime(String crisisID){
    String currentDateTimeString = "" + Calendar.DATE + Calendar.getInstance().getTime();
    mDatabase.child("crisis").child(crisisID).child("arrivalTime").setValue(currentDateTimeString);
}
 
开发者ID:panzerama,项目名称:Dispatch,代码行数:4,代码来源:CrisisManager.java

示例14: getAllOrdersCount

public PieChartData getAllOrdersCount(String restaurantId, int kind) {
    float[] time;
    if (kind == Calendar.DATE) time = new float[24];
    else if (kind == Calendar.WEEK_OF_YEAR) time = new float[7];
    else time = new float[31];
    for (int i = 0; i < time.length; i++) time[i] = 0;

    List<String> ordersList = getOrders(restaurantId);

    Calendar calendar = Calendar.getInstance();
    Order order;
    for (String orderKey : ordersList) {
        order = orderRepository.get(orderKey);
        if (checkTime(order.getDate(), kind)) {
            calendar.setTime(order.getDate());
            if (kind == Calendar.DATE)
                time[calendar.get(Calendar.HOUR_OF_DAY)] += 1.0f;
            else if (kind == Calendar.WEEK_OF_YEAR)
                time[calendar.get(Calendar.DAY_OF_WEEK)-1] += 1.0f;
            else
                time[calendar.get(Calendar.DAY_OF_MONTH)] += 1.0f;
        }
    }

    Integer count = 0;
    for (float t : time) if (t != 0) ++count;

    PieChartData data = new PieChartData(count);
    String[] xData = data.getXData();
    float[] yData = data.getYData();

    Integer j = 0;
    for (int i = 0; i < time.length; i++) {
        if (time[i] != 0) {
            yData[j] = time[i];


            String label = "";
            if (kind == Calendar.DATE) {
                if (i < 10) label += '0';
                label += String.valueOf(i) + "h - ";
                if (i + 1 < 10) label += '0';
                label += String.valueOf(i + 1) + 'h';
            } else if (kind == Calendar.WEEK_OF_YEAR) {
                if (i == 0) label = "Sunday";
                else if (i == 1) label = "Monday";
                else if (i == 2) label = "Tuesday";
                else if (i == 3) label = "Wednesday";
                else if (i == 4) label = "Thursday";
                else if (i == 5) label = "Friday";
                else if (i == 6) label = "Saturday";
            } else {
                label = "Day number " + String.valueOf(i) + " of the month.";
            }
            xData[j] = label;

            ++j;
        }
    }

    data.setXData(xData);
    data.setYData(yData);
    return data;
}
 
开发者ID:Wisebite,项目名称:wisebite_android,代码行数:64,代码来源:RestaurantService.java


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