本文整理汇总了Java中java.util.Calendar.YEAR属性的典型用法代码示例。如果您正苦于以下问题:Java Calendar.YEAR属性的具体用法?Java Calendar.YEAR怎么用?Java Calendar.YEAR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.YEAR属性的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: getInterval
/**
* 获取时间间隔类型
*
* @param field
* 时间间隔类型
* @return 日历的时间间隔
*/
protected static int getInterval(String field) {
String tmpField = field.toUpperCase();
if (DEFAULT_YEAR.equals(tmpField)) {
return Calendar.YEAR;
} else if (DEFAULT_MONTH.equals(tmpField)) {
return Calendar.MONTH;
} else if (DEFAULT_DATE.equals(tmpField)) {
return Calendar.DATE;
} else if (DEFAULT_HOUR.equals(tmpField)) {
return Calendar.HOUR;
} else if (DEFAULT_MINUTE.equals(tmpField)) {
return Calendar.MINUTE;
} else {
return Calendar.SECOND;
}
}
示例5: 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;
}
}
示例6: 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;
}
}
示例7: compareDate
/**
* 根据单位字段比较两个日期
*
* @param date
* 日期1
* @param otherDate
* 日期2
* @param withUnit
* 单位字段,从Calendar field取值
* @return 等于返回0值, 大于返回大于0的值 小于返回小于0的值
*/
public static int compareDate(Date date, Date otherDate, int withUnit) {
Calendar dateCal = Calendar.getInstance();
dateCal.setTime(date);
Calendar otherDateCal = Calendar.getInstance();
otherDateCal.setTime(otherDate);
switch (withUnit) {
case Calendar.YEAR:
dateCal.clear(Calendar.MONTH);
otherDateCal.clear(Calendar.MONTH);
case Calendar.MONTH:
dateCal.set(Calendar.DATE, 1);
otherDateCal.set(Calendar.DATE, 1);
case Calendar.DATE:
dateCal.set(Calendar.HOUR_OF_DAY, 0);
otherDateCal.set(Calendar.HOUR_OF_DAY, 0);
case Calendar.HOUR:
dateCal.clear(Calendar.MINUTE);
otherDateCal.clear(Calendar.MINUTE);
case Calendar.MINUTE:
dateCal.clear(Calendar.SECOND);
otherDateCal.clear(Calendar.SECOND);
case Calendar.SECOND:
dateCal.clear(Calendar.MILLISECOND);
otherDateCal.clear(Calendar.MILLISECOND);
case Calendar.MILLISECOND:
break;
default:
throw new IllegalArgumentException("withUnit 单位字段 " + withUnit + " 不合法!!");
}
return dateCal.compareTo(otherDateCal);
}
示例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: createDateSpinner
private JSpinner createDateSpinner(Calendar calendar) {
Date initDate = calendar.getTime();
calendar.add(Calendar.YEAR, -100);
Date earliestDate = calendar.getTime();
calendar.add(Calendar.YEAR, 200);
Date latestDate = calendar.getTime();
SpinnerDateModel spinnerDateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);
JSpinner dateSpinner = new JSpinner(spinnerDateModel);
dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner, "MM/yyyy"));
dateSpinner.setName("date-spinner");
return dateSpinner;
}
示例10: createDateSpinner
static void createDateSpinner() {
Calendar calendar = Calendar.getInstance();
Date initDate = calendar.getTime();
calendar.add(Calendar.YEAR, -1);
Date earliestDate = calendar.getTime();
calendar.add(Calendar.YEAR, 1);
Date latestDate = calendar.getTime();
SpinnerModel dateModel = new SpinnerDateModel(initDate,
earliestDate,
latestDate,
Calendar.YEAR);
spinner = new JSpinner();
spinner.setModel(dateModel);
}
示例11: 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 + "].");
}
}
示例12: getConfiguration
protected StatisticsRetrieverConfiguration getConfiguration() {
final int rollerInitTrauncateTo = Calendar.MONTH;
final int statisticsSize = 12;
final int rollerStep = Calendar.MONTH;
final int cutOffBefore = Calendar.YEAR;
return new StatisticsRetrieverConfiguration(rollerInitTrauncateTo,
statisticsSize,
rollerStep,
cutOffBefore);
}
示例13: 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");
}
}
示例14: getTimeRelativeTo
public long getTimeRelativeTo(long time)
{
int valueToUse = -(int) value;
int field = 0;
if (getUnit() == TimeUnit.MILLISECONDS)
{
field = Calendar.MILLISECOND;
//we do our own adjustment as calendar cannot handle a long.
time -= value;
valueToUse = 0;
}
else if (getUnit() == TimeUnit.SECONDS)
field = Calendar.SECOND;
else if (getUnit() == TimeUnit.MINUTES)
field = Calendar.MINUTE;
else if (getUnit() == TimeUnit.HOURS)
field = Calendar.HOUR;
else if (getUnit() == TimeUnit.DAYS)
field = Calendar.DATE;
else if (getUnit() == TimeUnit.WEEKS)
field = Calendar.WEEK_OF_MONTH;
else if (getUnit() == TimeUnit.MONTHS)
field = Calendar.MONTH;
else if (getUnit() == TimeUnit.YEARS)
field = Calendar.YEAR;
calendar.setTimeInMillis(time);
calendar.add(field, valueToUse);
return calendar.getTime().getTime();
}
示例15: getConfiguration
protected StatisticsRetrieverConfiguration getConfiguration() {
final int rollerInitTrauncateTo = Calendar.MONTH;
final int statisticsSize = DEFAULT_STATS_MONTHS;
final int rollerStep = Calendar.MONTH;
final int cutOffBefore = Calendar.YEAR;
return new StatisticsRetrieverConfiguration(rollerInitTrauncateTo,
statisticsSize,
rollerStep,
cutOffBefore);
}