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 calculateDayOfWeek(Date date) { final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.setTime(date);//from w ww.j a va 2 s.c om return calendar.get(Calendar.DAY_OF_WEEK); }
From source file:Main.java
public static Calendar getLastFriday(Calendar cal, int offset) { int dayofweek; cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + offset); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); dayofweek = cal.get(Calendar.DAY_OF_WEEK); if (dayofweek < Calendar.FRIDAY) cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 7 + Calendar.FRIDAY - dayofweek); else/* w ww .j a v a 2s . c o m*/ cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) + Calendar.FRIDAY - dayofweek); return cal; }
From source file:Main.java
public static int getWeek(int year, int month, int day) { Date date = new Date(year - 1900, month - 1, day); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);// w w w .ja v a 2 s.c o m int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); return dayOfWeek; }
From source file:Main.java
public static int getWeekOfDateDecimal(Date dt) { int[] weekDays = { 6, 0, 1, 2, 3, 4, 5 }; Calendar cal = Calendar.getInstance(); cal.setTime(dt);/*from w w w . jav a 2s .com*/ int w = cal.get(Calendar.DAY_OF_WEEK) - 1; if (w < 0) w = 0; return weekDays[w]; }
From source file:Main.java
public static int getWeek(int year, int month) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.get(Calendar.DAY_OF_WEEK) - 1; }
From source file:Main.java
public static int getWeekOfFirstDay(int year, int month) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.get(Calendar.DAY_OF_WEEK); }
From source file:Main.java
public static int getDay(int y, int m, int d) { if (m < 0 || m > 11) return -1; Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, y);//from w w w . j av a 2s.c om c.set(Calendar.MONTH, m); c.set(Calendar.DATE, d); return c.get(Calendar.DAY_OF_WEEK) - 1; }
From source file:Main.java
public static String getShortFormattedDate(Date date, Locale locale) { Calendar calendarToday = Calendar.getInstance(); Calendar calendarDate = Calendar.getInstance(); calendarDate.setTime(date);/* w w w. j a v a 2 s . c o m*/ if (calendarToday.get(Calendar.DAY_OF_WEEK) == calendarDate.get(Calendar.DAY_OF_WEEK)) { return new SimpleDateFormat("HH:mm", locale).format(date); } else { return new SimpleDateFormat("dd/MM", locale).format(date); } }
From source file:Main.java
public static String[] getWeekDays() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); String[] weekDays = new String[7]; for (int i = 0; i < 7; i++) { weekDays[i] = WEEK_DAYS_FORMAT.format(calendar.getTime()); calendar.add(Calendar.DATE, 1); }//from w w w. j ava 2 s . c o m return weekDays; }
From source file:Main.java
public static String[] getShortWeekDays() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); String[] weekDays = new String[7]; for (int i = 0; i < 7; i++) { weekDays[i] = SHORT_WEEK_DAYS_FORMAT.format(calendar.getTime()); calendar.add(Calendar.DATE, 1); }/*from ww w . j av a 2 s.c o m*/ return weekDays; }