當前位置: 首頁>>代碼示例>>Java>>正文


Java MutableDateTime.setMonthOfYear方法代碼示例

本文整理匯總了Java中org.joda.time.MutableDateTime.setMonthOfYear方法的典型用法代碼示例。如果您正苦於以下問題:Java MutableDateTime.setMonthOfYear方法的具體用法?Java MutableDateTime.setMonthOfYear怎麽用?Java MutableDateTime.setMonthOfYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.MutableDateTime的用法示例。


在下文中一共展示了MutableDateTime.setMonthOfYear方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setDateTime

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
/**
 * Sets the correct part of a {@link DateTime} corresponding to a
 * {@link SqlDatePartFunction}.
 *
 * @param value  The value to be set for the dateTime with the sqlDatePartFn
 * @param sqlDatePartFn  The function used to extract part of a date with sql.
 * @param dateTime  The original dateTime to create a copy of.
 */
protected void setDateTime(int value, SqlDatePartFunction sqlDatePartFn, MutableDateTime dateTime) {
    if (YEAR.equals(sqlDatePartFn)) {
        dateTime.setYear(value);
    } else if (MONTH.equals(sqlDatePartFn)) {
        dateTime.setMonthOfYear(value);
    } else if (WEEK.equals(sqlDatePartFn)) {
        dateTime.setWeekOfWeekyear(value);
        dateTime.setDayOfWeek(1);
    } else if (DAYOFYEAR.equals(sqlDatePartFn)) {
        dateTime.setDayOfYear(value);
    } else if (HOUR.equals(sqlDatePartFn)) {
        dateTime.setHourOfDay(value);
    } else if (MINUTE.equals(sqlDatePartFn)) {
        dateTime.setMinuteOfHour(value);
    } else if (SECOND.equals(sqlDatePartFn)) {
        dateTime.setSecondOfMinute(value);
    } else {
        throw new IllegalArgumentException("Can't set value " + value + " for " + sqlDatePartFn);
    }
}
 
開發者ID:yahoo,項目名稱:fili,代碼行數:29,代碼來源:SqlTimeConverter.java

示例2: getMode0257

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int dayOfYear = cal.getDayOfYear();

    if (dayOfYear < firstD) return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
    else return yr * 100 + (dayOfYear - firstD) / 7 +1;
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:20,代碼來源:MYearWeek.java

示例3: getMode0257

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr); 
    cal.setMonthOfYear(mo); 
    cal.setDayOfMonth(da); 

    int dayOfYear = cal.getDayOfYear(); 

    if (dayOfYear < firstD) return modes[lowestVal].getWeek(cal, yr-1, 12, 31);
    else return (dayOfYear - firstD) / 7 +1;
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:20,代碼來源:MWeek.java

示例4: convertToAvro

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
    if (xts == null) {
        return null;
    }

    MutableDateTime dateTime = new MutableDateTime();
    try {
        dateTime.setYear(xts.getYear());
        dateTime.setMonthOfYear(xts.getMonth());
        dateTime.setDayOfMonth(xts.getDay());
        dateTime.setHourOfDay(xts.getHour());
        dateTime.setMinuteOfHour(xts.getMinute());
        dateTime.setSecondOfMinute(xts.getSecond());
        dateTime.setMillisOfSecond(xts.getMillisecond());

        DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
        if (tz != null) {
            dateTime.setZoneRetainFields(tz);
        }

        return Long.valueOf(dateTime.getMillis());
    } catch (IllegalArgumentException e) {
        throw new ComponentException(e);
    }
}
 
開發者ID:Talend,項目名稱:components,代碼行數:27,代碼來源:XMLGregorianCalendarToDateTimeConverter.java

示例5: onDateSet

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public void onDateSet(DatePicker view, int year, int month, int day) {
    // Do something with the date chosen by the user
    mutableDateTimeDate = new MutableDateTime();
    mutableDateTimeDate.setYear(year);
    mutableDateTimeDate.setMonthOfYear(month + 1);
    mutableDateTimeDate.setDayOfMonth(day);
    toShowResult.setText(DateTimeUtils.getStringPatternFromDateTime(toShowResult.getContext().getString(R.string.date_register_formatter), mutableDateTimeDate));
}
 
開發者ID:scott7462,項目名稱:Udacity-Capstone-Project,代碼行數:9,代碼來源:DatePickerFragment.java

示例6: getMode1346

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);

    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int week = cal.getDayOfYear() - (firstD +1 ); // Sun/Mon
    if (firstD < 4)
    {
        if (week < 0) return  modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
        else return yr * 100 + week / 7 + 1;
    }
    else
    {
        if (week < 0) return yr * 100 + 1;
        else return yr * 100 + week / 7 + 2;
    }
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:28,代碼來源:MYearWeek.java

示例7: getMode1346

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);

    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay) 
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int week = cal.getDayOfYear() - (firstD +1 ); // Sun/Mon
    if (firstD < 4)
    {
        if (week < 0) return modes[lowestVal].getWeek(cal, yr-1, 12, 31);
        else return week / 7 + 1;
    }
    else
    {
        if (week < 0) return 1;
        else return week / 7 + 2;
    }
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:28,代碼來源:MWeek.java

示例8: getTimeAfter

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public DateTime getTimeAfter(DateTime dateTime) {
    try {
        String[] fixedCronExp = appendYearField(expression.split("\\s+"));
        validate(fixedCronExp);

        MutableDateTime mdt = dateTime.toMutableDateTime();
        mdt.setMillisOfSecond(0);

        List<Integer> secondValues = parse(secondParsers, fixedCronExp[AbstractParser.DurationField.SECOND.getIndex()], dateTime, AbstractParser.DurationField.SECOND);
        List<Integer> minuteValues = parse(minuteParsers, fixedCronExp[AbstractParser.DurationField.MINUTE.getIndex()], dateTime, AbstractParser.DurationField.MINUTE);
        List<Integer> hourValues = parse(hourParsers, fixedCronExp[AbstractParser.DurationField.HOUR.getIndex()], dateTime, AbstractParser.DurationField.HOUR);
        List<Integer> monthValues = parse(monthParsers, fixedCronExp[AbstractParser.DurationField.MONTH.getIndex()], dateTime, AbstractParser.DurationField.MONTH);
        List<Integer> yearValues = parse(yearParsers, fixedCronExp[AbstractParser.DurationField.YEAR.getIndex()], dateTime, AbstractParser.DurationField.YEAR);

        int yearStartIndex = searchNotLessThanIndex(yearValues, mdt.getYear());
        for (int yearIndex = yearStartIndex, yearLen = yearValues.size(); yearIndex < yearLen; yearIndex++) {
            int year = yearValues.get(yearIndex);
            mdt.setYear(year);
            int monthStartIndex = (year == dateTime.getYear()) ? searchNotLessThanIndex(monthValues, dateTime.getMonthOfYear()) : 0;

            for (int monthIndex = monthStartIndex, monthLen = monthValues.size(); monthIndex < monthLen; monthIndex++) {
                int month = monthValues.get(monthIndex);
                mdt.setMonthOfYear(month);
                List<Integer> dayValues = parseDayValueList(fixedCronExp, mdt.toDateTime());
                int dayStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear())
                        ? searchNotLessThanIndex(dayValues, dateTime.getDayOfMonth()) : 0;

                int maxDayOfMonth = mdt.toDateTime().dayOfMonth().withMaximumValue().toLocalDate().getDayOfMonth();
                for (int dayIndex = dayStartIndex, dayLen = dayValues.size(); dayIndex < dayLen; dayIndex++) {
                    int day = dayValues.get(dayIndex);
                    if (day > maxDayOfMonth) {
                        break;
                    }
                    mdt.setDayOfMonth(day);
                    int hourStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear() && day == dateTime.getDayOfMonth())
                            ? searchNotLessThanIndex(hourValues, dateTime.getHourOfDay()) : 0;

                    for (int hourIndex = hourStartIndex, hourLen = hourValues.size(); hourIndex < hourLen; hourIndex++) {
                        int hour = hourValues.get(hourIndex);
                        mdt.setHourOfDay(hour);
                        int minuteStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
                                && day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay())
                                ? searchNotLessThanIndex(minuteValues, dateTime.getMinuteOfHour()) : 0;

                        for (int minuteIndex = minuteStartIndex, minuteLen = minuteValues.size(); minuteIndex < minuteLen; minuteIndex++) {
                            int minute = minuteValues.get(minuteIndex);
                            int secondStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
                                    && day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay() && minute == dateTime.getMinuteOfHour())
                                    ? searchNotLessThanIndex(secondValues, dateTime.getSecondOfMinute()) : 0;
                            mdt.setMinuteOfHour(minute);
                            for (int secondIndex = secondStartIndex, secondLen = secondValues.size(); secondIndex < secondLen; secondIndex++) {
                                int second = secondValues.get(secondIndex);
                                mdt.setSecondOfMinute(second);
                                if (mdt.isAfter(dateTime)) {
                                    return mdt.toDateTime();
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
    return null;
}
 
開發者ID:stuxuhai,項目名稱:jcron,代碼行數:68,代碼來源:CronExpression.java

示例9: getTimeBefore

import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public DateTime getTimeBefore(DateTime dateTime) {
    try {
        String[] fixedCronExp = appendYearField(expression.split("\\s+"));
        validate(fixedCronExp);

        MutableDateTime mdt = dateTime.toMutableDateTime();
        mdt.setMillisOfSecond(0);

        List<Integer> secondValues = parse(secondParsers, fixedCronExp[AbstractParser.DurationField.SECOND.getIndex()], dateTime, AbstractParser.DurationField.SECOND);
        List<Integer> minuteValues = parse(minuteParsers, fixedCronExp[AbstractParser.DurationField.MINUTE.getIndex()], dateTime, AbstractParser.DurationField.MINUTE);
        List<Integer> hourValues = parse(hourParsers, fixedCronExp[AbstractParser.DurationField.HOUR.getIndex()], dateTime, AbstractParser.DurationField.HOUR);
        List<Integer> monthValues = parse(monthParsers, fixedCronExp[AbstractParser.DurationField.MONTH.getIndex()], dateTime, AbstractParser.DurationField.MONTH);
        List<Integer> yearValues = parse(yearParsers, fixedCronExp[AbstractParser.DurationField.YEAR.getIndex()], dateTime, AbstractParser.DurationField.YEAR);

        int yearStartIndex = searchNotGreaterThanIndex(yearValues, mdt.getYear());
        for (int yearIndex = yearStartIndex; yearIndex >= 0; yearIndex--) {
            int year = yearValues.get(yearIndex);
            mdt.setYear(year);
            int monthStartIndex = (year == dateTime.getYear()) ? searchNotGreaterThanIndex(monthValues, dateTime.getMonthOfYear())
                    : monthValues.size() - 1;

            for (int monthIndex = monthStartIndex; monthIndex >= 0; monthIndex--) {
                int month = monthValues.get(monthIndex);
                mdt.setMonthOfYear(month);
                List<Integer> dayValues = parseDayValueList(fixedCronExp, mdt.toDateTime());
                int dayStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear())
                        ? searchNotGreaterThanIndex(dayValues, dateTime.getDayOfMonth()) : dayValues.size() - 1;

                int maxDayOfMonth = mdt.toDateTime().dayOfMonth().withMaximumValue().toLocalDate().getDayOfMonth();
                for (int dayIndex = dayStartIndex; dayIndex >= 0; dayIndex--) {
                    int day = dayValues.get(dayIndex);
                    if (day > maxDayOfMonth) {
                        break;
                    }
                    mdt.setDayOfMonth(day);
                    int hourStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear() && day == dateTime.getDayOfMonth())
                            ? searchNotGreaterThanIndex(hourValues, dateTime.getHourOfDay()) : hourValues.size() - 1;

                    for (int hourIndex = hourStartIndex; hourIndex >= 0; hourIndex--) {
                        int hour = hourValues.get(hourIndex);
                        mdt.setHourOfDay(hour);
                        int minuteStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
                                && day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay())
                                ? searchNotGreaterThanIndex(minuteValues, dateTime.getMinuteOfHour()) : minuteValues.size() - 1;

                        for (int minuteIndex = minuteStartIndex; minuteIndex >= 0; minuteIndex--) {
                            int minute = minuteValues.get(minuteIndex);
                            mdt.setMinuteOfHour(minute);
                            int secondStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
                                    && day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay() && minute == dateTime.getMinuteOfHour())
                                    ? searchNotGreaterThanIndex(secondValues, dateTime.getSecondOfMinute()) : secondValues.size() - 1;

                            for (int secondIndex = secondStartIndex; secondIndex >= 0; secondIndex--) {
                                int second = secondValues.get(secondIndex);
                                mdt.setSecondOfMinute(second);
                                if (mdt.isBefore(dateTime)) {
                                    return mdt.toDateTime();
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }

    return null;
}
 
開發者ID:stuxuhai,項目名稱:jcron,代碼行數:71,代碼來源:CronExpression.java


注:本文中的org.joda.time.MutableDateTime.setMonthOfYear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。