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