本文整理匯總了Java中java.util.Calendar.HOUR_OF_DAY屬性的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.HOUR_OF_DAY屬性的具體用法?Java Calendar.HOUR_OF_DAY怎麽用?Java Calendar.HOUR_OF_DAY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.HOUR_OF_DAY屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: translate
private static int translate(final IntervalUnit unit) {
switch (unit) {
case DAY:
return Calendar.DAY_OF_YEAR;
case HOUR:
return Calendar.HOUR_OF_DAY;
case MINUTE:
return Calendar.MINUTE;
case MONTH:
return Calendar.MONTH;
case SECOND:
return Calendar.SECOND;
case MILLISECOND:
return Calendar.MILLISECOND;
case WEEK:
return Calendar.WEEK_OF_YEAR;
case YEAR:
return Calendar.YEAR;
default:
throw new IllegalArgumentException("Unknown IntervalUnit");
}
}
示例2: getDateEnd
/**
* @param dateAndResolution
* @return String date
*/
public static String getDateEnd(Pair<Date, Integer> dateAndResolution)
{
Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
cal.setTime(dateAndResolution.getFirst());
switch (dateAndResolution.getSecond())
{
case Calendar.YEAR:
cal.set(Calendar.MONTH, cal.getActualMaximum(Calendar.MONTH));
case Calendar.MONTH:
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
case Calendar.DAY_OF_MONTH:
cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
case Calendar.HOUR_OF_DAY:
cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE));
case Calendar.MINUTE:
cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND));
case Calendar.SECOND:
cal.set(Calendar.MILLISECOND, cal.getActualMaximum(Calendar.MILLISECOND));
case Calendar.MILLISECOND:
default:
}
SimpleDateFormat formatter = CachingDateFormat.getSolrDatetimeFormat();
formatter.setTimeZone(UTC_TIMEZONE);
return formatter.format(cal.getTime());
}
示例3: getDateStart
/**
* @param dateAndResolution
* @return String date
*/
public static String getDateStart(Pair<Date, Integer> dateAndResolution)
{
Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
cal.setTime(dateAndResolution.getFirst());
switch (dateAndResolution.getSecond())
{
case Calendar.YEAR:
cal.set(Calendar.MONTH, cal.getActualMinimum(Calendar.MONTH));
case Calendar.MONTH:
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
case Calendar.DAY_OF_MONTH:
cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
case Calendar.HOUR_OF_DAY:
cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
case Calendar.MINUTE:
cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
case Calendar.SECOND:
cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
case Calendar.MILLISECOND:
default:
}
SimpleDateFormat formatter = CachingDateFormat.getSolrDatetimeFormat();
formatter.setTimeZone(UTC_TIMEZONE);
return formatter.format(cal.getTime());
}
示例4: previous
/**
* Operation is based on java util calendar in order to support daylight
* saving times.
*/
public TimeSlice previous() {
long newStart = start;
long newEnd = end;
Calendar temp = Calendar.getInstance();
temp.setTimeInMillis(start);
int field = 0;
switch (period) {
case HOUR:
field = Calendar.HOUR_OF_DAY;
break;
case DAY:
field = Calendar.DAY_OF_MONTH;
break;
case WEEK:
field = Calendar.WEEK_OF_YEAR;
break;
case MONTH:
field = Calendar.MONTH;
break;
default:
break;
}
temp.add(field, -1);
newStart = temp.getTimeInMillis();
temp.setTimeInMillis(end);
temp.add(field, -1);
newEnd = temp.getTimeInMillis();
return new TimeSlice(newStart, newEnd, period);
}
示例5: 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;
}
示例6: 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;
}
}
示例7: 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;
}
}
示例8: Adjustment
public Adjustment(int field, int amount) {
this.originalField = field;
switch (field) {
case CALENDAR_FIELD_YEAR:
this.calendarField = Calendar.YEAR;
break;
case CALENDAR_FIELD_MONTH:
this.calendarField = Calendar.MONTH;
break;
case CALENDAR_FIELD_DAY:
this.calendarField = Calendar.DAY_OF_YEAR;
break;
case CALENDAR_FIELD_HOUR:
this.calendarField = Calendar.HOUR_OF_DAY;
break;
case CALENDAR_FIELD_MINUTE:
this.calendarField = Calendar.MINUTE;
break;
case CALENDAR_FIELD_SECOND:
this.calendarField = Calendar.SECOND;
break;
case CALENDAR_FIELD_MILLISECOND:
this.calendarField = Calendar.MILLISECOND;
break;
}
this.amount = amount;
}
示例9: getMethod
static ValueSource getMethod(IndexFieldData<?> fieldData, String fieldName, String method) {
switch (method) {
case GETVALUE_METHOD:
return new FieldDataValueSource(fieldData, MultiValueMode.MIN);
case ISEMPTY_METHOD:
return new EmptyMemberValueSource(fieldData);
case SIZE_METHOD:
return new CountMethodValueSource(fieldData);
case MINIMUM_METHOD:
return new FieldDataValueSource(fieldData, MultiValueMode.MIN);
case MAXIMUM_METHOD:
return new FieldDataValueSource(fieldData, MultiValueMode.MAX);
case AVERAGE_METHOD:
return new FieldDataValueSource(fieldData, MultiValueMode.AVG);
case MEDIAN_METHOD:
return new FieldDataValueSource(fieldData, MultiValueMode.MEDIAN);
case SUM_METHOD:
return new FieldDataValueSource(fieldData, MultiValueMode.SUM);
case COUNT_METHOD:
return new CountMethodValueSource(fieldData);
case GET_YEAR_METHOD:
return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.YEAR);
case GET_MONTH_METHOD:
return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.MONTH);
case GET_DAY_OF_MONTH_METHOD:
return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.DAY_OF_MONTH);
case GET_HOUR_OF_DAY_METHOD:
return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.HOUR_OF_DAY);
case GET_MINUTES_METHOD:
return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.MINUTE);
case GET_SECONDS_METHOD:
return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.SECOND);
default:
throw new IllegalArgumentException("Member method [" + method + "] does not exist for date field [" + fieldName + "].");
}
}
示例10: translate
private static int translate(IntervalUnit unit) {
switch(unit) {
case DAY : return Calendar.DAY_OF_YEAR;
case HOUR : return Calendar.HOUR_OF_DAY;
case MINUTE : return Calendar.MINUTE;
case MONTH : return Calendar.MONTH;
case SECOND : return Calendar.SECOND;
case MILLISECOND : return Calendar.MILLISECOND;
case WEEK : return Calendar.WEEK_OF_YEAR;
case YEAR : return Calendar.YEAR;
default : throw new IllegalArgumentException("Unknown IntervalUnit");
}
}
示例11: formatDateDiff
public static String formatDateDiff(Calendar fromDate, Calendar toDate) {
boolean future = false;
if (toDate.equals(fromDate)) {
return I18N.tr("now");
}
if (toDate.after(fromDate)) {
future = true;
}
StringBuilder sb = new StringBuilder();
int[] types = { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND };
String[] names = {
I18N.tr("year"), I18N.tr("years"),
I18N.tr("month"), I18N.tr("months"),
I18N.tr("day"), I18N.tr("days"),
I18N.tr("hour"), I18N.tr("hours"),
I18N.tr("minute"), I18N.tr("minutes"),
I18N.tr("second"), I18N.tr("seconds")
};
int accuracy = 0;
for (int i = 0; i < types.length; i++) {
if (accuracy > 2) {
break;
}
int diff = dateDiff(types[i], fromDate, toDate, future);
if (diff > 0) {
accuracy++;
sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
}
}
if (sb.length() == 0) {
return "now";
}
return sb.toString().trim();
}
示例12: truncateDate
/**
* @param date
* @param truncateAt
*/
public static Date truncateDate(final Date date, final int truncateAt) {
final Calendar source = Calendar.getInstance();
source.clear();
source.setTime(date);
final Calendar result = Calendar.getInstance();
result.clear();
result.set(Calendar.YEAR, source.get(Calendar.YEAR));
final TimeZone sourceTimeZone = source.getTimeZone();
result.setTimeZone(sourceTimeZone);
if (truncateAt == Calendar.HOUR_OF_DAY) {
result.set(Calendar.HOUR_OF_DAY, source.get(Calendar.HOUR_OF_DAY));
result.set(Calendar.MONTH, source.get(Calendar.MONTH));
result.set(Calendar.DAY_OF_MONTH, source.get(Calendar.DAY_OF_MONTH));
result.set(Calendar.DST_OFFSET, source.get(Calendar.DST_OFFSET));
} else if (truncateAt == Calendar.DAY_OF_MONTH) {
result.set(Calendar.MONTH, source.get(Calendar.MONTH));
result.set(Calendar.DAY_OF_MONTH, source.get(Calendar.DAY_OF_MONTH));
// if (log.isDebugEnabled()) log.debug("result.get(Calendar.HOUR_OF_DAY): " + result.get(Calendar.HOUR_OF_DAY));
} else if (truncateAt == Calendar.MONTH) {
result.set(Calendar.MONTH, source.get(Calendar.MONTH));
} else if (truncateAt == Calendar.YEAR) { // NOPMD
// do nothing
} else { // NOPMD
throw new IllegalArgumentException("Unknown truncateAt");
}
return result.getTime();
}
示例13: compareTime
/**
* <p>Compares a calendar time value to another, indicating whether it is
* equal, less then or more than at a specified level.</p>
*
* @param value The Calendar value.
* @param compare The <code>Calendar</code> to check the value against.
* @param field The field <i>level</i> to compare to - e.g. specifying
* <code>Calendar.MINUTE</code> will compare the hours and minutes
* portions of the calendar.
* @return Zero if the first value is equal to the second, -1
* if it is less than the second or +1 if it is greater than the second.
*/
protected int compareTime(Calendar value, Calendar compare, int field) {
int result = 0;
// Compare Hour
result = calculateCompareResult(value, compare, Calendar.HOUR_OF_DAY);
if (result != 0 || (field == Calendar.HOUR || field == Calendar.HOUR_OF_DAY)) {
return result;
}
// Compare Minute
result = calculateCompareResult(value, compare, Calendar.MINUTE);
if (result != 0 || field == Calendar.MINUTE) {
return result;
}
// Compare Second
result = calculateCompareResult(value, compare, Calendar.SECOND);
if (result != 0 || field == Calendar.SECOND) {
return result;
}
// Compare Milliseconds
if (field == Calendar.MILLISECOND) {
return calculateCompareResult(value, compare, Calendar.MILLISECOND);
}
throw new IllegalArgumentException("Invalid field: " + field);
}
示例14: setLoadSchedule
public void setLoadSchedule(LoadSchedule schedule) {
if (schedule == null) {
schedule = LoadSchedule.getDefaultLoadSchedule();
}
lowLoadRadio.setSelected(schedule.isLowLoadEnabled());
normalLoadRadio.setSelected(!lowLoadRadio.isSelected());
normalLoadConsPerSystemField.setText("" + schedule.getNormalLoadMaxConnCount());
normalLoadConsPerNodeField.setText("" + schedule.getNormalLoadMaxConnPerNodeCount());
lowLoadConsPerSystemField.setText("" + schedule.getLowLoadMaxConnCount());
lowLoadConsPerNodeField.setText("" + schedule.getLowLoadMaxConnPerNodeCount());
Date startTime = schedule.getLowLoadStartTime();
SpinnerDateModel startModel = new SpinnerDateModel(startTime, null, null,
Calendar.HOUR_OF_DAY);
lowLoadStartTimeSpinner.setModel(startModel);
lowLoadStartTimeSpinner
.setEditor(new JSpinner.DateEditor(lowLoadStartTimeSpinner, "HH:mm"));
Date endTime = schedule.getLowLoadEndTime();
SpinnerDateModel endModel = new SpinnerDateModel(endTime, null, null, Calendar.HOUR_OF_DAY);
lowLoadEndTimeSpinner.setModel(endModel);
lowLoadEndTimeSpinner.setEditor(new JSpinner.DateEditor(lowLoadEndTimeSpinner, "HH:mm"));
enableLowLoadUIComponents(lowLoadRadio.isSelected());
}
示例15: 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;
}