List of usage examples for java.util Calendar DAY_OF_WEEK
int DAY_OF_WEEK
To view the source code for java.util Calendar DAY_OF_WEEK.
Click Source Link
get
and set
indicating the day of the week. From source file:Main.java
public static int getDayForWeekInMonth(int date, Calendar calendar) { if (date < 1 || date > 31) { return 1; }/* w w w. j a v a 2s . c o m*/ calendar.set(Calendar.DAY_OF_MONTH, date); return calendar.get(Calendar.DAY_OF_WEEK) - 1; }
From source file:Main.java
public static Date getNextSaturday(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//w w w. ja v a 2 s. c om while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { cal.add(Calendar.DAY_OF_WEEK, 1); } return cal.getTime(); }
From source file:Main.java
public static String getWochentagFromSystemDate() { Calendar rightNow = Calendar.getInstance(TimeZone.getDefault()); int dayOfWeek = rightNow.get(Calendar.DAY_OF_WEEK); switch (dayOfWeek) { case 1:/* w w w. ja va2 s . c o m*/ return "Sonntag"; case 2: return "Montag"; case 3: return "Dienstag"; case 4: return "Mittwoch"; case 5: return "Donnerstag"; case 6: return "Freitag"; case 7: return "Samstag"; } return ""; }
From source file:Main.java
public static int getWeekOfDate() { Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.setTime(new Date()); int k = calendar.get(Calendar.DAY_OF_WEEK) - 1; if (k < 1) k = 7;//from ww w . j a v a 2 s. com return k; }
From source file:Main.java
public static int getWeekDay(Date date) { return getCalendar(date).get(Calendar.DAY_OF_WEEK); }
From source file:Util.java
public static Date getSunday(Date today) { Calendar cal = Calendar.getInstance(); cal.setTime(today);/*w w w . ja va 2s. com*/ int dow = cal.get(Calendar.DAY_OF_WEEK); while (dow != Calendar.SUNDAY) { int date = cal.get(Calendar.DATE); int month = cal.get(Calendar.MONTH); int year = cal.get(Calendar.YEAR); if (date == getMonthLastDate(month, year)) { if (month == Calendar.DECEMBER) { month = Calendar.JANUARY; cal.set(Calendar.YEAR, year + 1); } else { month++; } cal.set(Calendar.MONTH, month); date = 1; } else { date++; } cal.set(Calendar.DATE, date); dow = cal.get(Calendar.DAY_OF_WEEK); } return cal.getTime(); }
From source file:Main.java
/** * Get First Date of month/*from www . j av a2s . c om*/ */ public static int getDayFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.DAY_OF_WEEK); }
From source file:Main.java
public static int getCurrentFirstWeekdayOfMoth() { int today = getCurrentDate(); calendar.set(Calendar.DATE, 1); int weekday = calendar.get(Calendar.DAY_OF_WEEK) - 1; calendar.set(Calendar.DATE, today); return weekday; }
From source file:Main.java
public static Date getLastWeekMonday() { Calendar cal = Calendar.getInstance(); for (int mondays = 0; mondays < 2;) { if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) { mondays++;//www.j ava 2s .com } cal.add(Calendar.DAY_OF_WEEK, -1); } return cal.getTime(); }
From source file:Main.java
public static int getDayOfWeek(Date date) { Calendar calendar = Calendar.getInstance(); if (date == null) date = new Date(); calendar.setTime(date);/*w w w . j ava 2s . c om*/ return calendar.get(Calendar.DAY_OF_WEEK); }