List of usage examples for java.util Calendar DAY_OF_MONTH
int DAY_OF_MONTH
To view the source code for java.util Calendar DAY_OF_MONTH.
Click Source Link
get
and set
indicating the day of the month. From source file:Main.java
/** * Check if date1 is after date2 or not//from w w w.j a v a2s . c om * @return true if date1 after date 2, otherwise false. */ public static boolean isBefore(Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR)) { return true; } else if (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.MONTH) < cal2.get(Calendar.MONTH)) { return true; } else if (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) && cal1.get(Calendar.DAY_OF_MONTH) < cal2.get(Calendar.DAY_OF_MONTH)) { return true; } return false; }
From source file:Main.java
/** * Get current month end day/*from w w w . j av a2s .c om*/ * * @return */ public static int getCurrentMonthEndDay() { Calendar calendar = Calendar.getInstance(); return calendar.getActualMaximum(Calendar.DAY_OF_MONTH); }
From source file:Main.java
/** * Get current month first day// ww w . j a va 2 s .c o m * * @return */ public static int getCurrentMonthFirstDay() { Calendar calendar = Calendar.getInstance(); return calendar.getActualMinimum(Calendar.DAY_OF_MONTH); }
From source file:Main.java
public static boolean isTodayInCalendar(Calendar calendar) { return todayCalendar.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH) && todayCalendar.get(Calendar.MONTH) == calendar.get(Calendar.MONTH) && todayCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR); }
From source file:Main.java
public static Date getDateTimeFrom(int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.MONTH, monthOfYear - 1); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); Date ret = calendar.getTime(); return ret;// w w w . j av a2 s.c om }
From source file:Main.java
/** Helper method - creates a Phoenix date <I>String</I> from a Date object. @param dteValue <I>Date</I> object to be converted. @return A <I>String</I> that follows the format "YYYY-MM-DDTHH:NN:SS.00000". */// ww w . ja va 2 s . com public static String getXMLStringFromDate(Date dteValue) { if (null == dteValue) return null; Calendar pCalendar = Calendar.getInstance(); pCalendar.setTime(dteValue); // Return the String value. // Special treatment for the month because the current implementation // values January as 0. Code below should work if that ever changes. return pCalendar.get(Calendar.YEAR) + "-" + padNumber(pCalendar.get(Calendar.MONTH) + 1 - Calendar.JANUARY) + "-" + padNumber(pCalendar.get(Calendar.DAY_OF_MONTH)) + "T" + padNumber(pCalendar.get(Calendar.HOUR_OF_DAY)) + ":" + padNumber(pCalendar.get(Calendar.MINUTE)) + ":" + padNumber(pCalendar.get(Calendar.SECOND)); }
From source file:Main.java
/** * Get a list of initial and end calendar of months in the range received * @param cStart Calendar date to start/*from w ww.j av a2s.com*/ * @param cEnd Calendar date to end * @return List<Pair<Calendar, Calendar>> list of calendars (initial and end) */ public static List<Pair<Calendar, Calendar>> getRangeInMonths(Calendar cStart, Calendar cEnd) { //generate the list List<Pair<Calendar, Calendar>> calendars = new ArrayList<>(); //from the first calendar start adding a month until the actual calendar is after the end Calendar cActual = generateCalendar(cStart); cActual.set(Calendar.DAY_OF_MONTH, 1); Calendar c0; Calendar cF; while (cActual.compareTo(cEnd) < 0) { //calendar start if (calendars.size() == 0) { c0 = generateCalendar(cStart); } else { c0 = generateCalendar(cActual); } //increment a month cActual.add(Calendar.MONTH, 1); //calendar end if (cActual.after(cEnd)) { cF = generateCalendar(cEnd); } else { cF = generateCalendar(cActual); //remove 1 day to set the last day of the month cF.add(Calendar.DAY_OF_YEAR, -1); } //add the pair to the list calendars.add(new Pair<Calendar, Calendar>(c0, cF)); } //return the list return calendars; }
From source file:Main.java
/** * Get next month first day/* w ww . jav a2 s. c o m*/ */ public static int getNextMonthFirstDay() { Calendar lastDate = Calendar.getInstance(); lastDate.add(Calendar.MONTH, 1); lastDate.set(Calendar.DATE, 1); return lastDate.getActualMinimum(Calendar.DAY_OF_MONTH); }
From source file:Main.java
/** * Get last month first day/*w w w.j a v a 2s .co m*/ */ public static int getLastMonthFirstDay() { Calendar lastDate = Calendar.getInstance(); lastDate.set(Calendar.DATE, 1); lastDate.add(Calendar.MONTH, -1); return lastDate.getActualMinimum(Calendar.DAY_OF_MONTH); }
From source file:Main.java
public static boolean isSameDateInCalendar(Calendar calendar, Date date) { Calendar dateCalendar = Calendar.getInstance(); dateCalendar.setTime(date);//from w ww .ja v a2 s .c o m return dateCalendar.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH) && dateCalendar.get(Calendar.MONTH) == calendar.get(Calendar.MONTH) && dateCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR); }