本文整理了Java中java.util.Calendar.getActualMaximum()
方法的一些代码示例,展示了Calendar.getActualMaximum()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.getActualMaximum()
方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:getActualMaximum
[英]Returns the maximum value of the given field for the current date. For example, the maximum number of days in the current month.
[中]返回当前日期给定字段的最大值。例如,当前月份的最大天数。
代码示例来源:origin: stackoverflow.com
Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);
代码示例来源:origin: jenkinsci/jenkins
void setTo(Calendar c, int i) {
c.set(field,Math.min(i-offset, c.getActualMaximum(field)));
}
代码示例来源:origin: apache/hive
private boolean isLastDayOfMonth(Calendar cal) {
int maxDd = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
int dd = cal.get(Calendar.DAY_OF_MONTH);
return dd == maxDd;
}
}
代码示例来源:origin: stackoverflow.com
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date convertedDate = dateFormat.parse(date);
Calendar c = Calendar.getInstance();
c.setTime(convertedDate);
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
代码示例来源:origin: org.apache.commons/commons-lang3
if (val.get(Calendar.YEAR) > 280000000) {
throw new ArithmeticException("Calendar value too large for accurate calculations");
final Date date = val.getTime();
long time = date.getTime();
boolean done = false;
final int millisecs = val.get(Calendar.MILLISECOND);
if (ModifyType.TRUNCATE == modType || millisecs < 500) {
time = time - millisecs;
final int seconds = val.get(Calendar.SECOND);
if (!done && (ModifyType.TRUNCATE == modType || seconds < 30)) {
time = time - (seconds * 1000L);
if (val.get(Calendar.DATE) == 1) {
val.add(Calendar.DATE, 15);
} else {
val.add(Calendar.DATE, -15);
val.add(Calendar.MONTH, 1);
final int max = val.getActualMaximum(aField[0]);
offset = val.get(aField[0]) - min;
val.set(aField[0], val.get(aField[0]) - offset);
代码示例来源:origin: pentaho/pentaho-kettle
row[index] = cal.getTime();
break;
case TYPE_SYSTEM_INFO_THIS_DAY_START:
cal = Calendar.getInstance();
row[index] = cal.getTime();
break;
case TYPE_SYSTEM_INFO_THIS_DAY_END:
cal.add( Calendar.DAY_OF_MONTH, 1 );
cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
cal.add( Calendar.MONTH, -3 - ( cal.get( Calendar.MONTH ) % 3 ) );
cal.add( Calendar.MONTH, -1 - ( cal.get( Calendar.MONTH ) % 3 ) );
cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DATE ) );
cal.add( Calendar.MONTH, 0 - ( cal.get( Calendar.MONTH ) % 3 ) );
cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DATE ) );
cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DATE ) );
代码示例来源:origin: cachecats/coderiver
/**
* 获取日期时间当月的总天数,如2017-02-13,返回28
*
* @param date
* @return
*/
public static int getDaysOfMonth(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.getActualMaximum(Calendar.DATE);
}
代码示例来源:origin: stackoverflow.com
public static boolean isLeapYear(int year) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
return cal.getActualMaximum(Calendar.DAY_OF_YEAR) > 365;
}
代码示例来源:origin: jamesagnew/hapi-fhir
cal.set(Calendar.YEAR, parseInt(value, value.substring(0, 4), 0, 9999));
precision = TemporalPrecisionEnum.YEAR;
if (length > 4) {
validateLengthIsAtLeast(value, 7);
int monthVal = parseInt(value, value.substring(5, 7), 1, 12) - 1;
cal.set(Calendar.MONTH, monthVal);
precision = TemporalPrecisionEnum.MONTH;
if (length > 7) {
validateCharAtIndexIs(value, 7, '-');
validateLengthIsAtLeast(value, 10);
cal.set(Calendar.DATE, 1); // for some reason getActualMaximum works incorrectly if date isn't set
int actualMaximum = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum));
precision = TemporalPrecisionEnum.DAY;
return cal.getTime();
代码示例来源:origin: jaydenxiao2016/AndroidFire
/**
* 描述:计算两个日期所差的天数.
*
* @param date1 第一个时间的毫秒表示
* @param date2 第二个时间的毫秒表示
* @return int 所差的天数
*/
public static int getOffectDay(long date1, long date2) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
//先判断是否同年
int y1 = calendar1.get(Calendar.YEAR);
int y2 = calendar2.get(Calendar.YEAR);
int d1 = calendar1.get(Calendar.DAY_OF_YEAR);
int d2 = calendar2.get(Calendar.DAY_OF_YEAR);
int maxDays = 0;
int day = 0;
if (y1 - y2 > 0) {
maxDays = calendar2.getActualMaximum(Calendar.DAY_OF_YEAR);
day = d1 - d2 + maxDays;
} else if (y1 - y2 < 0) {
maxDays = calendar1.getActualMaximum(Calendar.DAY_OF_YEAR);
day = d1 - d2 - maxDays;
} else {
day = d1 - d2;
}
return day;
}
代码示例来源:origin: wdullaer/MaterialDateTimePicker
private Calendar 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);
}
return mDateRangeLimiter.setToNearestDate(calendar);
}
代码示例来源:origin: rey5137/material
private long getNextMonthlyEventTime(Calendar cal, long start, long now){
if(mRepeatSetting == MONTH_SAME_DAY){
cal.setTimeInMillis(now);
int nowMonthYear = cal.get(Calendar.MONTH) + cal.get(Calendar.YEAR) * 12;
int startMonthYear = cal.get(Calendar.MONTH) + cal.get(Calendar.YEAR) * 12;
int startDay = cal.get(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.YEAR, monthYear / 12);
cal.set(Calendar.MONTH, monthYear % 12);
cal.set(Calendar.DAY_OF_MONTH, Math.min(startDay, cal.getActualMaximum(Calendar.DAY_OF_MONTH)));
代码示例来源:origin: stackoverflow.com
public static int daysBetween(Calendar day1, Calendar day2){
Calendar dayOne = (Calendar) day1.clone(),
dayTwo = (Calendar) day2.clone();
if (dayOne.get(Calendar.YEAR) == dayTwo.get(Calendar.YEAR)) {
return Math.abs(dayOne.get(Calendar.DAY_OF_YEAR) - dayTwo.get(Calendar.DAY_OF_YEAR));
} else {
if (dayTwo.get(Calendar.YEAR) > dayOne.get(Calendar.YEAR)) {
//swap them
Calendar temp = dayOne;
dayOne = dayTwo;
dayTwo = temp;
}
int extraDays = 0;
int dayOneOriginalYearDays = dayOne.get(Calendar.DAY_OF_YEAR);
while (dayOne.get(Calendar.YEAR) > dayTwo.get(Calendar.YEAR)) {
dayOne.add(Calendar.YEAR, -1);
// getActualMaximum() important for leap years
extraDays += dayOne.getActualMaximum(Calendar.DAY_OF_YEAR);
}
return extraDays - dayTwo.get(Calendar.DAY_OF_YEAR) + dayOneOriginalYearDays ;
}
}
代码示例来源:origin: apache/drill
protected Calendar addMonth(Date d, int numMonths) {
calendar.setTime(d);
boolean lastDatOfMonth = isLastDayOfMonth(calendar);
calendar.add(Calendar.MONTH, numMonths);
if (lastDatOfMonth) {
int maxDd = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Calendar.DAY_OF_MONTH, maxDd);
}
return calendar;
}
代码示例来源:origin: wildfly/wildfly
/**
* Returns the last date of the month represented by the passed <code>cal</code>
*
* @param calendar The {@link java.util.Calendar} whose {@link java.util.Calendar#MONTH} field will be used
* as the current month
* @return
*/
public static int getLastDateOfMonth(Calendar calendar) {
Calendar tmpCal = new GregorianCalendar(calendar.getTimeZone());
tmpCal.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
tmpCal.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
tmpCal.set(Calendar.DAY_OF_MONTH, 1);
return tmpCal.getActualMaximum(Calendar.DAY_OF_MONTH);
}
代码示例来源:origin: rey5137/material
private void calculateMonthView(){
mCalendar.set(Calendar.DAY_OF_MONTH, 1);
mCalendar.set(Calendar.MONTH, mMonth);
mCalendar.set(Calendar.YEAR, mYear);
mMaxDay = mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int dayOfWeek = mCalendar.get(Calendar.DAY_OF_WEEK);
mFirstDayCol = dayOfWeek < mFirstDayOfWeek ? dayOfWeek + 7 - mFirstDayOfWeek : dayOfWeek - mFirstDayOfWeek;
mMonthText = mCalendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()) + " " + String.format(YEAR_FORMAT, mYear);
}
代码示例来源:origin: apache/drill
protected Calendar lastDay(Date d) {
calendar.setTime(d);
int maxDd = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Calendar.DAY_OF_MONTH, maxDd);
return calendar;
}
}
代码示例来源:origin: apache/drill
int monDiffInt = (cal1.get(YEAR) - cal2.get(YEAR)) * 12 + (cal1.get(MONTH) - cal2.get(MONTH));
if (cal1.get(DATE) == cal2.get(DATE)
|| (cal1.get(DATE) == cal1.getActualMaximum(DATE) && cal2.get(DATE) == cal2
.getActualMaximum(DATE))) {
output.set(monDiffInt);
return output;
代码示例来源:origin: apache/hive
private Calendar addMonth(int numMonths) {
boolean lastDatOfMonth = isLastDayOfMonth(calendar);
calendar.add(Calendar.MONTH, numMonths);
if (lastDatOfMonth) {
int maxDd = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Calendar.DAY_OF_MONTH, maxDd);
}
return calendar;
}
代码示例来源:origin: apache/hive
int monDiffInt = (cal1.get(YEAR) - cal2.get(YEAR)) * 12 + (cal1.get(MONTH) - cal2.get(MONTH));
if (cal1.get(DATE) == cal2.get(DATE)
|| (cal1.get(DATE) == cal1.getActualMaximum(DATE) && cal2.get(DATE) == cal2
.getActualMaximum(DATE))) {
output.set(monDiffInt);
return output;
内容来源于网络,如有侵权,请联系作者删除!