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
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); boolean b = cal.isSet(Calendar.DAY_OF_MONTH); System.out.println("Day of month is set: " + b); // clear day of month cal.clear(Calendar.DAY_OF_MONTH); // determine if the given calendar field has a value set b = cal.isSet(Calendar.DAY_OF_MONTH); System.out.println("Day of month is set: " + b); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar cal = Calendar.getInstance(); int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28 }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println(now.getTime()); System.out.println(now.get(Calendar.DAY_OF_MONTH)); }
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); // 15-04-2012 calendar.set(Calendar.DAY_OF_MONTH, 15); calendar.set(Calendar.YEAR, 2012); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MONTH, 3); Date start = calendar.getTime(); // 15-06-2012 calendar.set(Calendar.MONTH, 5); Date end = calendar.getTime(); calendar.setTime(start);/*ww w. j a v a 2 s. co m*/ Date d = null; while ((d = calendar.getTime()).before(end) || d.equals(end)) { int day = calendar.get(Calendar.DAY_OF_WEEK); if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) { System.out.println(d); } calendar.add(Calendar.DAY_OF_MONTH, 1); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar cal = new GregorianCalendar(2000, Calendar.FEBRUARY, 1); int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 29 }
From source file:Main.java
public static void main(String[] args) { Calendar today = new GregorianCalendar(); Calendar purchased = new GregorianCalendar(); purchased.add(Calendar.DAY_OF_MONTH, 1); Calendar lastActDate = new GregorianCalendar(); lastActDate.setTimeInMillis(today.getTimeInMillis() - purchased.getTimeInMillis()); }
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.DAY_OF_MONTH, 1); // day of week for first date of month int weekOfFirstDate = calendar.get(Calendar.WEEK_OF_YEAR); int lastDateOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); calendar.set(Calendar.DAY_OF_MONTH, lastDateOfMonth); // day of week for last date of month int weekOfLastDate = calendar.get(Calendar.WEEK_OF_YEAR); calendar.roll(Calendar.MONTH, false); int lastDateOfPrevMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); int weeksToDisplay = weekOfLastDate - weekOfFirstDate + 1; int[] days = new int[weeksToDisplay * 7]; int firstDayPosition = 3; // fill previous month int x = lastDateOfPrevMonth; for (int i = firstDayPosition - 1; i >= 0; i--) { days[i] = x--;//from www.j a va 2 s .co m } // fill current month for (int i = 1; i < lastDateOfMonth + 1; i++) { days[firstDayPosition - 1 + i] = i; } // fill next month int j = 1; for (int i = lastDateOfMonth + firstDayPosition; i < days.length; i++) { days[i] = j++; } for (int i = 0; i < days.length; i++) { if (i % 7 == 0) { System.out.println(); } System.out.print(days[i] + "\t"); } }
From source file:KVMCalendar.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Date date = new Date(); cal.setTime(date);//from w w w . j av a2s .c o m int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); System.out.println("Day is " + day + ", month is " + month); final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000L; long offset = date.getTime(); offset += 20 * MILLIS_PER_DAY; date.setTime(offset); cal.setTime(date); month = cal.get(Calendar.MONTH); day = cal.get(Calendar.DAY_OF_MONTH); System.out.println("In 20 days time, day will " + day + ", month will be " + month); System.out.println(cal); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2007); cal.set(Calendar.DAY_OF_YEAR, 180); System.out.println("Calendar date is: " + cal.getTime()); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); System.out.println("Calendar day of month: " + dayOfMonth); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); System.out.println("Calendar day of week: " + dayOfWeek); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); int day = cal.get(Calendar.DATE); int month = cal.get(Calendar.MONTH) + 1; int year = cal.get(Calendar.YEAR); int dow = cal.get(Calendar.DAY_OF_WEEK); int dom = cal.get(Calendar.DAY_OF_MONTH); int doy = cal.get(Calendar.DAY_OF_YEAR); System.out.println("Current Date: " + cal.getTime()); System.out.println("Day: " + day); System.out.println("Month: " + month); System.out.println("Year: " + year); System.out.println("Day of Week: " + dow); System.out.println("Day of Month: " + dom); System.out.println("Day of Year: " + doy); }