本文整理汇总了Java中com.ibm.icu.util.Calendar.set方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.set方法的具体用法?Java Calendar.set怎么用?Java Calendar.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.Calendar
的用法示例。
在下文中一共展示了Calendar.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public java.sql.Date convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
String trimStr = obj.trim();
if (trimStr.length() == 0) {
return null;
}
DateFormat df = null;
if (UtilValidate.isEmpty(formatString)) {
df = UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, locale);
} else {
df = UtilDateTime.toDateFormat(formatString, timeZone, locale);
}
try {
java.util.Date parsedDate = df.parse(trimStr);
Calendar cal = UtilDateTime.toCalendar(parsedDate, timeZone, locale);
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
return new java.sql.Date(cal.getTimeInMillis());
} catch (ParseException e) {
throw new ConversionException(e);
}
}
示例2: 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;
}
示例3: includesDate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
@Override
public boolean includesDate(Calendar cal) {
int minute = cal.get(Calendar.MINUTE);
if (minute == this.start || minute == this.end) {
return true;
}
Calendar compareCal = (Calendar) cal.clone();
compareCal.set(Calendar.MINUTE, this.start);
while (compareCal.get(Calendar.MINUTE) != this.end) {
if (compareCal.get(Calendar.MINUTE) == minute) {
return true;
}
compareCal.add(Calendar.MINUTE, 1);
}
return false;
}
示例4: getMonthNames
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/**
* Returns a List of month name Strings - suitable for calendar headings.
*
* @param locale
* @return List of month name Strings
*/
public static List<String> getMonthNames(Locale locale) {
Calendar tempCal = Calendar.getInstance(locale);
tempCal.set(Calendar.MONTH, Calendar.JANUARY);
SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM", locale);
List<String> resultList = new ArrayList<String>();
for (int i = Calendar.JANUARY; i <= tempCal.getActualMaximum(Calendar.MONTH); i++) {
resultList.add(dateFormat.format(tempCal.getTime()));
tempCal.roll(Calendar.MONTH, 1);
}
return resultList;
}
示例5: adjustDayInMonthIfNeeded
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private void adjustDayInMonthIfNeeded(Calendar calendar) {
int day = calendar.get(Calendar.DAY_OF_MONTH);
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
if (day > daysInMonth) {
calendar.set(Calendar.DAY_OF_MONTH, daysInMonth);
}
setToNearestDate(calendar);
}
示例6: getTimeStampFromIntervalScope
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static Timestamp getTimeStampFromIntervalScope(String iScope, int iCount, Timestamp thruDate) {
iCount--;
if (iCount < 0)
iCount = getIntervalDefaultCount(iScope);
Calendar calendar = (thruDate != null) ? toCalendar(thruDate) : Calendar.getInstance();
if (iScope.equals("hour")) {
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - iCount);
} else if (iScope.equals("day")) {
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - iCount);
} else if (iScope.equals("week")) {
calendar.set(Calendar.DAY_OF_WEEK, 1);
calendar.set(Calendar.WEEK_OF_YEAR, calendar.get(Calendar.WEEK_OF_YEAR) - iCount);
} else if (iScope.equals("month")) {
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - iCount);
} else if (iScope.equals("quarter")) {
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - (iCount * 3));
} else if (iScope.equals("semester")) {
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - (iCount * 6));
} else if (iScope.equals("year")) {
calendar.set(Calendar.DAY_OF_YEAR, 1);
calendar.set(Calendar.MONTH, 1);
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - iCount);
}
return UtilDateTime.toTimestamp(calendar.getTime());
}
示例7: getEndDate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
@Override
public Calendar getEndDate() {
if (selectableDays != null) return selectableDays[selectableDays.length - 1];
if (mMaxDate != null) return mMaxDate;
Calendar output = Calendar.getInstance();
output.set(Calendar.YEAR, mMaxYear);
output.set(Calendar.DAY_OF_MONTH, 31);
output.set(Calendar.MONTH, Calendar.DECEMBER);
return output;
}
示例8: getLatestDate
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static Date getLatestDate() {
Calendar cal = getCalendarInstance(TimeZone.getTimeZone("GMT"), Locale.getDefault());
cal.set(Calendar.YEAR, cal.getActualMaximum(Calendar.YEAR));
cal.set(Calendar.MONTH, cal.getActualMaximum(Calendar.MONTH));
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
return cal.getTime();
}
示例9: testDateTimeConverters
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public void testDateTimeConverters() throws Exception {
Calendar cal = Calendar.getInstance();
long currentTime = cal.getTimeInMillis();
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
long longTime = cal.getTimeInMillis(); // Start of day today
assertNotEquals("currentTime and longTime are not equal", currentTime, longTime);
java.util.Date utilDate = new java.util.Date(longTime);
java.sql.Date sqlDate = new java.sql.Date(longTime);
java.sql.Timestamp timestamp = new java.sql.Timestamp(longTime);
// Source class = java.util.Date
assertConversion("DateToLong", new DateTimeConverters.DateToLong(), utilDate, longTime);
assertConversion("DateToSqlDate", new DateTimeConverters.DateToSqlDate(), utilDate, new java.sql.Date(longTime));
assertConversion("DateToString", new DateTimeConverters.DateToString(), utilDate, utilDate.toString());
assertConversion("DateToTimestamp", new DateTimeConverters.DateToTimestamp(), utilDate, timestamp);
// Source class = java.sql.Date
assertConversion("SqlDateToLong", new DateTimeConverters.DateToLong(), sqlDate, longTime);
assertConversion("SqlDateToDate", new DateTimeConverters.SqlDateToDate(), sqlDate, utilDate);
assertConversion("SqlDateToString", new DateTimeConverters.SqlDateToString(), sqlDate, sqlDate.toString());
assertConversion("SqlDateToTimestamp", new DateTimeConverters.SqlDateToTimestamp(), sqlDate, timestamp);
// Source class = java.sql.Timestamp
assertConversion("TimestampToLong", new DateTimeConverters.DateToLong(), timestamp, longTime);
assertConversion("TimestampToDate", new DateTimeConverters.TimestampToDate(), timestamp, utilDate);
assertConversion("TimestampToSqlDate", new DateTimeConverters.TimestampToSqlDate(), timestamp, sqlDate);
assertConversion("TimestampToString", new DateTimeConverters.TimestampToString(), timestamp, timestamp.toString());
// Source class = java.lang.Long
assertConversion("LongToDate", new DateTimeConverters.NumberToDate(), longTime, utilDate);
assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), longTime, sqlDate);
assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), currentTime, sqlDate); //Test conversion to start of day
assertConversion("LongToTimestamp", new DateTimeConverters.NumberToTimestamp(), longTime, timestamp);
// Source class = java.lang.String
assertConversion("StringToTimestamp", new DateTimeConverters.StringToTimestamp(), timestamp.toString(), timestamp);
//assertConversion("StringToDate", new DateTimeConverters.StringToDate(), utilDate.toString(), utilDate);
//assertConversion("StringToSqlDate", new DateTimeConverters.StringToSqlDate(), sqlDate.toString(), sqlDate);
}
示例10: getShortDayNamesString
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
public static String getShortDayNamesString(int[] daysOfWeek) {
String dayNames = null;
Format formatter = new SimpleDateFormat(TWO_CHARACTER_SHORT_DAY_PATTERN, Locale.getDefault());
Calendar calendar = Calendar.getInstance();
for(int day = 0; day < daysOfWeek.length; day++) {
calendar.set(Calendar.DAY_OF_WEEK, daysOfWeek[day]);
if (day == 0) {
dayNames = formatter.format(calendar.getTime()).toUpperCase(Locale.getDefault());
} else {
dayNames += " " + formatter.format(calendar.getTime()).toUpperCase(Locale.getDefault());
}
}
return dayNames;
}
示例11: 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);
}
示例12: 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;
}
示例13: 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;
}
示例14: getDayValueList
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
/** Returns a List of Maps containing day of the week values.
* @param locale
* @return List of Maps. Each Map has a
* <code>description</code> entry and a <code>value</code> entry.
*/
public static List<Map<String, Object>> getDayValueList(Locale locale) {
Calendar tempCal = Calendar.getInstance(locale);
tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek());
SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE", locale);
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(7);
for (int i = 0; i < 7; i++) {
result.add(UtilMisc.toMap("description", (Object)dateFormat.format(tempCal.getTime()), "value", tempCal.get(Calendar.DAY_OF_WEEK)));
tempCal.roll(Calendar.DAY_OF_WEEK, 1);
}
return result;
}
示例15: 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;
}