Java Code Examples for java.util.Calendar.getActualMaximum()
The following are Jave code examples for showing how to use
getActualMaximum() of the
java.util.Calendar
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: CosmoCalendar File: DateUtils.java View Source Code | 7 votes |
public static Date getLastDayOfWeek(@Nullable Date date) { Calendar calendar = Calendar.getInstance(); if (date != null) { calendar.setTime(date); } calendar.clear(Calendar.HOUR_OF_DAY); calendar.clear(Calendar.HOUR); if (calendar.get(Calendar.DAY_OF_MONTH) == calendar.getActualMaximum(Calendar.DAY_OF_MONTH) && calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { return calendar.getTime(); } calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMaximum(Calendar.DAY_OF_WEEK)); while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { calendar.add(Calendar.DATE, 1); } return calendar.getTime(); }
Example 2
Project: AssistantBySDK File: TimeUtils.java View Source Code | 6 votes |
/** * 获取本日的n个月前的日期,如本日=2015-03-01,n=3,则输出2014-12-01 * * @param n * @return */ public static Date getSomeMonthsBefore(int n) { Calendar cl = Calendar.getInstance(); cl.set(Calendar.HOUR_OF_DAY, 0); cl.set(Calendar.MINUTE, 0); cl.set(Calendar.SECOND, 0); cl.set(Calendar.MILLISECOND, 0); int year = cl.get(Calendar.YEAR); int month = cl.get(Calendar.MONTH); int day = cl.get(Calendar.DAY_OF_MONTH); int by = n / 12; int bm = n % 12; if (by > 0) { year -= by; } if (bm > month) { year--; } month = (12 + month - bm) % 12; cl.set(Calendar.YEAR, year); cl.set(Calendar.MONTH, month); cl.set(Calendar.DAY_OF_MONTH, 1); if (day > cl.getActualMaximum(Calendar.DAY_OF_MONTH)) {//cl为n个月前的1号,如果该月的最大日数比现在的日数小,则取当月的最大日数 cl.set(Calendar.DAY_OF_MONTH, cl.getActualMaximum(Calendar.DAY_OF_MONTH)); } else { cl.set(Calendar.DAY_OF_MONTH, day); } return cl.getTime(); }
Example 3
Project: boohee_v5.6 File: DatePickerDialog.java View Source Code | 6 votes |
private void adjustDayInMonthIfNeeded(Calendar calendar) { int day = calendar.get(5); int daysInMonth = calendar.getActualMaximum(5); if (day > daysInMonth) { calendar.set(5, daysInMonth); } setToNearestDate(calendar); }
Example 4
Project: SER316-Dresden File: JNCalendar.java View Source Code | 6 votes |
/** * Builds calendar based on the first and last day of the week. */ void setCalendarParameters() { int d = 1; Calendar cal = _date.getCalendar(); if (Configuration.get("FIRST_DAY_OF_WEEK").equals("mon")) { cal.setFirstDayOfWeek(Calendar.MONDAY); d = 2; } else cal.setFirstDayOfWeek(Calendar.SUNDAY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.getTime(); firstDay = cal.get(Calendar.DAY_OF_WEEK) - d; if (firstDay == -1) firstDay = 6; daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); }
Example 5
Project: SER316-Ingolstadt File: JNCalendar.java View Source Code | 6 votes |
void setCalendarParameters() { int d = 1; Calendar cal = _date.getCalendar(); if (Configuration.get("FIRST_DAY_OF_WEEK").equals("mon")) { cal.setFirstDayOfWeek(Calendar.MONDAY); d = 2; } else cal.setFirstDayOfWeek(Calendar.SUNDAY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.getTime(); firstDay = cal.get(Calendar.DAY_OF_WEEK) - d; if (firstDay == -1) firstDay = 6; daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); }
Example 6
Project: quickhybrid-android File: DateUtil.java View Source Code | 5 votes |
public static int getDaysOfYM(int year, int month) { Calendar time = Calendar.getInstance(); time.clear(); time.set(Calendar.YEAR, year); time.set(Calendar.MONTH, month - 1); int day = time.getActualMaximum(Calendar.DAY_OF_MONTH); return day; }
Example 7
Project: Reinickendorf_SER316 File: CalendarDate.java View Source Code | 5 votes |
public CalendarDate(int day, int month, int year) { _year = year; _month = month; Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, _year); cal.set(Calendar.MONTH, _month);cal.getTime(); int dmax = cal.getActualMaximum(Calendar.DAY_OF_MONTH); if (day <= dmax) _day = day; else _day = dmax; }
Example 8
Project: azeroth File: DateUtils.java View Source Code | 5 votes |
/** * 返回传入时间月份的最后一天 * */ public static Date lastDayOfMonth(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); int value = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, value); return cal.getTime(); }
Example 9
Project: TechnicalAnalysisTool File: DateUtil.java View Source Code | 5 votes |
/** * Return if the date is the last Day of the year * @param calendar Calendar object in query * @param countryName Country Name * @return true if it is otherwise return false */ public static boolean isLastDayofYear(Calendar calendar, String countryName){ Calendar local = (Calendar)calendar.clone(); if(local == null) return false; if (isWeekend(local)){ return false; } if (isPublicHoliday(local, countryName)){ return false; } int maxDayOfYear = local.getActualMaximum(Calendar.DAY_OF_YEAR); int dayOfYearh = local.get(Calendar.DAY_OF_YEAR); if (dayOfYearh == maxDayOfYear){ return true; } else { while(local.get(Calendar.DAY_OF_YEAR) != maxDayOfYear){ local.add(Calendar.DAY_OF_YEAR, 1); if (!isWeekend(local) && !isPublicHoliday(local, countryName)){ return false; } } if (isWeekend(local) || isPublicHoliday(local, countryName)){ return true; }else{ return false; } } }
Example 10
Project: RackMonthPicker File: MonthAdapter.java View Source Code | 5 votes |
public int getEndDate() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, selectedItem + 1); cal.set(Calendar.DAY_OF_MONTH, selectedItem + 1); int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); return maxDay; }
Example 11
Project: SER316-Munich File: CalendarDate.java View Source Code | 5 votes |
public CalendarDate(int day, int month, int year) { _year = year; _month = month; Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, _year); cal.set(Calendar.MONTH, _month);cal.getTime(); int dmax = cal.getActualMaximum(Calendar.DAY_OF_MONTH); if (day <= dmax) _day = day; else _day = dmax; }
Example 12
Project: MonthView File: MonthView.java View Source Code | 5 votes |
/** * Set the calendar. * This calendar instance is the fundamental of this MonthView class. * * @param calendar the calendar you want this MonthView to show. */ public void setCalendar(Calendar calendar) { if (mCalendar != calendar) { mCalendar = calendar; Calendar preCalendar = (Calendar) mCalendar.clone(); preCalendar.add(Calendar.MONTH, -1); mDayOffset = getDayOffset(); mMonthDayCount = mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); mPreMonthDayCount = preCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); postInvalidate(); } }
Example 13
Project: spring-boot-wechat File: DateUtils.java View Source Code | 4 votes |
public static int getTotalDaysOfYear(Date date) { Calendar calendar = Calendar.getInstance(local); calendar.setTime(date); return calendar.getActualMaximum(6); }
Example 14
Project: spring-boot-wechat File: DateUtils.java View Source Code | 4 votes |
public static int getTotalDaysOfMonth(Date date) { Calendar calendar = Calendar.getInstance(local); calendar.setTime(date); return calendar.getActualMaximum(5); }
Example 15
Project: financisto1-holo File: MonthlyViewActivity.java View Source Code | 4 votes |
private int getLastDayOfMonth(int month, int year) { Calendar calCurr = GregorianCalendar.getInstance(); calCurr.set(year, month-1, 1); // Months are 0 to 11 return calCurr.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); }
Example 16
Project: quickhybrid-android File: DateUtil.java View Source Code | 4 votes |
public static int getDayNumsOfMonth(Date date) { Calendar time = Calendar.getInstance(); time.setTime(date); int day = time.getActualMaximum(Calendar.DAY_OF_MONTH); return day; }
Example 17
Project: date-helper File: DateHelper.java View Source Code | 3 votes |
/** * Antwortet ein Integer von 1-31 welcher die anzahl Tage des Monats * entspricht. Das Jahr muss wegen dem Schaltjahr bekannt sein. * * @param month Index des Monats * @param year Jahr in dem die anzahl Tage des Monats ermittelt werden * sollen. * @return int Anzahl Tage des Monats */ public static int getDaysInMonth(int month, int year) { Calendar calendar = getCalendar(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DATE, 1); return calendar.getActualMaximum(Calendar.DAY_OF_MONTH); }
Example 18
Project: mumu File: DateUtils.java View Source Code | 3 votes |
/** * 取得月天数 * * @param date * @return */ public static int getDayOfMonth(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); return c.getActualMaximum(Calendar.DAY_OF_MONTH); }
Example 19
Project: GoupilBot File: DateTimeLib.java View Source Code | 2 votes |
/** * Retourne le nombre de jours maximal dans un mois en tenant compte des années * bissextiles. * * @param date la date dont il faut examiner le mois * @return le nombre de jours maximal dans le mois extrait de la date */ public static int getMonthMaxDay(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); return cal.getActualMaximum(Calendar.DAY_OF_MONTH); }
Example 20
Project: marathonv5 File: HistoryTabController.java View Source Code | 2 votes |
/** * Convert a Java Date into a decimal number of days from beginning of year 0000 * * @param date The date to convert * @return date converted to decimal days */ private static double convertToDecimalMonth(Calendar date) { int month = (date.get(Calendar.YEAR) * 12) + date.get(Calendar.MONTH); double day = ((double)date.get(Calendar.DAY_OF_MONTH)-1d) / ((double)date.getActualMaximum(Calendar.DAY_OF_MONTH)-1d); return month + day; }