本文整理汇总了Java中com.ibm.icu.util.Calendar.add方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.add方法的具体用法?Java Calendar.add怎么用?Java Calendar.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.Calendar
的用法示例。
在下文中一共展示了Calendar.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: includesDate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
@Override
public boolean includesDate(Calendar cal) {
int month = cal.get(Calendar.MONTH);
if (month == this.start || month == this.end) {
return true;
}
Calendar compareCal = (Calendar) cal.clone();
while (compareCal.get(Calendar.MONTH) != this.start) {
compareCal.add(Calendar.MONTH, 1);
}
while (compareCal.get(Calendar.MONTH) != this.end) {
if (compareCal.get(Calendar.MONTH) == month) {
return true;
}
compareCal.add(Calendar.MONTH, 1);
}
return false;
}
示例2: getEvenStartingTime
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private static long getEvenStartingTime(long binLength) {
// binLengths should be a divisable evenly into 1 hour
long curTime = System.currentTimeMillis();
// find the first previous millis that are even on the hour
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(curTime));
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
while (cal.getTime().getTime() < (curTime - binLength)) {
cal.add(Calendar.MILLISECOND, (int) binLength);
}
return cal.getTime().getTime();
}
示例3: alignDayOfWeek
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
protected Calendar alignDayOfWeek(Calendar cal) {
cal.set(Calendar.DAY_OF_MONTH, 1);
if (this.occurrence > 0) {
while (cal.get(Calendar.DAY_OF_WEEK) != this.dayOfWeek) {
cal.add(Calendar.DAY_OF_MONTH, 1);
}
cal.add(Calendar.DAY_OF_MONTH, (this.occurrence - 1) * 7);
} else {
cal.add(Calendar.MONTH, 1);
cal.add(Calendar.DAY_OF_MONTH, -1);
while (cal.get(Calendar.DAY_OF_WEEK) != this.dayOfWeek) {
cal.add(Calendar.DAY_OF_MONTH, -1);
}
cal.add(Calendar.DAY_OF_MONTH, (this.occurrence + 1) * 7);
}
return cal;
}
示例4: initializeDefaultCenturyStart
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private void initializeDefaultCenturyStart(long baseTime) {
defaultCenturyBase = baseTime;
// clone to avoid messing up date stored in calendar object
// when this method is called while parsing
Calendar tmpCal = (Calendar)calendar.clone();
tmpCal.setTimeInMillis(baseTime);
tmpCal.add(Calendar.YEAR, -80);
defaultCenturyStart = tmpCal.getTime();
defaultCenturyStartYear = tmpCal.get(Calendar.YEAR);
}
示例5: isSubstitutionCandidate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
@Override
public boolean isSubstitutionCandidate(Calendar cal, TemporalExpression expressionToTest) {
Calendar checkCal = (Calendar) cal.clone();
checkCal.add(Calendar.MONTH, -1);
while (!includesDate(checkCal)) {
if (expressionToTest.includesDate(checkCal)) {
return true;
}
checkCal.add(Calendar.MONTH, -1);
}
return false;
}
示例6: getHourStart
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static Timestamp getHourStart(Timestamp stamp, int hoursLater, TimeZone timeZone, Locale locale) {
Calendar tempCal = toCalendar(stamp, timeZone, locale);
tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), tempCal.get(Calendar.HOUR_OF_DAY), 0, 0);
tempCal.add(Calendar.HOUR_OF_DAY, hoursLater);
Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
retStamp.setNanos(0);
return retStamp;
}
示例7: getHourEnd
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static Timestamp getHourEnd(Timestamp stamp, Long hoursLater, TimeZone timeZone, Locale locale) {
Calendar tempCal = toCalendar(stamp, timeZone, locale);
tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), tempCal.get(Calendar.HOUR_OF_DAY), 59, 59);
tempCal.add(Calendar.HOUR_OF_DAY, hoursLater.intValue());
Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
retStamp.setNanos(0);
return retStamp;
}
示例8: getDayEnd
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static Timestamp getDayEnd(Timestamp stamp, Long daysLater, TimeZone timeZone, Locale locale) {
Calendar tempCal = toCalendar(stamp, timeZone, locale);
tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
tempCal.add(Calendar.DAY_OF_MONTH, daysLater.intValue());
Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
retStamp.setNanos(0);
//MSSQL datetime field has accuracy of 3 milliseconds and setting the nano seconds cause the date to be rounded to next day
//retStamp.setNanos(999999999);
return retStamp;
}
示例9: getWeekStart
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static Timestamp getWeekStart(Timestamp stamp, int daysLater, int weeksLater, TimeZone timeZone, Locale locale) {
Calendar tempCal = toCalendar(stamp, timeZone, locale);
tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek());
tempCal.add(Calendar.WEEK_OF_MONTH, weeksLater);
Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
retStamp.setNanos(0);
return retStamp;
}
示例10: getMinuteRangeAsSet
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public Set<Integer> getMinuteRangeAsSet() {
Set<Integer> rangeSet = new TreeSet<Integer>();
if (this.start == this.end) {
rangeSet.add(this.start);
} else {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, this.start);
while (cal.get(Calendar.HOUR_OF_DAY) != this.end) {
rangeSet.add(cal.get(Calendar.HOUR_OF_DAY));
cal.add(Calendar.HOUR_OF_DAY, 1);
}
}
return rangeSet;
}
示例11: getMonthStart
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static Timestamp getMonthStart(Timestamp stamp, int daysLater, int monthsLater, TimeZone timeZone, Locale locale) {
Calendar tempCal = toCalendar(stamp, timeZone, locale);
tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), 1, 0, 0, 0);
tempCal.add(Calendar.MONTH, monthsLater);
tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
retStamp.setNanos(0);
return retStamp;
}
示例12: testDuration
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public void testDuration() throws Exception {
Calendar now = Calendar.getInstance();
TimeDuration zeroDuration = TimeDuration.ZeroTimeDuration;
assertFalse("zero equals null", zeroDuration.equals(null));
Calendar newTime = (Calendar) now.clone();
zeroDuration.addToCalendar(newTime);
assertEquals("zero same calendar", now, newTime);
assertDurationFields("zero(same zero calendar)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", new TimeDuration(zero, zero), false, true);
assertDurationFields("zero(same now calendar)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", new TimeDuration(now, now), false, true);
assertDurationFields("zero(empty parse)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.parseDuration(""), false, true);
assertDurationFields("zero(zero parse)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.parseDuration("0:0:0:0:0:0:0"), false, true);
assertDurationFields("zero(from null number)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.fromNumber(null), false, true);
assertDurationFields("zero(from null number)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.fromNumber(null), false, true);
assertDuration("millisecond", 0, 0, 0, 0, 0, 0, 1);
assertDuration("second", 0, 0 ,0 ,0, 0, 1, 0);
assertDuration("minute", 0, 0, 0, 0, 1, 0, 0);
assertDuration("hour", 0, 0, 0, 1, 0, 0, 0);
assertDuration("day", 0, 0, 1, 0, 0, 0, 0);
assertDuration("month", 0, 1, 0, 0, 0, 0, 0);
assertDuration("year", 1, 0, 0, 0, 0, 0, 0);
Calendar start = new com.ibm.icu.util.GregorianCalendar(1967, 1, 1, 0, 0, 0);
start.set(Calendar.MILLISECOND, 0);
Calendar end = (Calendar) start.clone();
end.add(Calendar.MILLISECOND, 1);
end.add(Calendar.SECOND, 1);
end.add(Calendar.MINUTE, 1);
end.add(Calendar.HOUR_OF_DAY, 1);
end.add(Calendar.DAY_OF_MONTH, 1);
end.add(Calendar.MONTH, 1);
end.add(Calendar.YEAR, 1);
assertDurationFields("pre-epoch elapsed time", 1, 1, 1, 1, 1, 1, 1, "1:1:1:1:1:1:1", new TimeDuration(start, end), false, false);
}
示例13: advanceCalendar
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private static int advanceCalendar(Calendar start, Calendar end, int units, int type) {
if (units >= 1) {
// Bother, the below needs explanation.
//
// If start has a day value of 31, and you add to the month,
// and the target month is not allowed to have 31 as the day
// value, then the day will be changed to a value that is in
// range. But, when the code needs to then subtract 1 from
// the month, because it has advanced to far, the day is *not*
// set back to the original value of 31.
//
// This bug can be triggered by having a duration of -1 day,
// then adding this duration to a calendar that represents 0
// milliseconds, then creating a new duration by using the 2
// Calendar constructor, with cal1 being 0, and cal2 being the
// new calendar that you added the duration to.
//
// To solve this problem, we make a temporary copy of the
// start calendar, and only modify it if we actually have to.
Calendar tmp = (Calendar) start.clone();
int tmpUnits = units;
tmp.add(type, tmpUnits);
while (tmp.after(end)) {
tmp.add(type, -1);
units--;
}
if (units != 0) {
start.add(type, units);
}
}
return units;
}
示例14: addToCalendar
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/** Add this time duration to a Calendar instance. Returns the original
* Calendar instance.
* @param cal
* @return <code>cal</code>
*/
public Calendar addToCalendar(Calendar cal) {
cal.add(Calendar.MILLISECOND, this.milliseconds);
cal.add(Calendar.SECOND, this.seconds);
cal.add(Calendar.MINUTE, this.minutes);
cal.add(Calendar.HOUR, this.hours);
cal.add(Calendar.DAY_OF_MONTH, this.days);
cal.add(Calendar.MONTH, this.months);
cal.add(Calendar.YEAR, this.years);
return cal;
}
示例15: adjustTimestamp
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static Timestamp adjustTimestamp(Timestamp stamp, Integer adjType, Integer adjQuantity) {
Calendar tempCal = toCalendar(stamp);
tempCal.add(adjType, adjQuantity);
return new Timestamp(tempCal.getTimeInMillis());
}