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 String getDayOfWeekString(int day) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, day); SimpleDateFormat format = new SimpleDateFormat("EEE", Locale.US); return format.format(calendar.getTime()); }
From source file:Main.java
/** * //from w w w.j a va 2 s. c o m * @return */ public static String ID_DayName() { Calendar cal = Calendar.getInstance(); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); String weekDayName = ""; if (Calendar.MONDAY == dayOfWeek) { weekDayName = "Senin"; } else if (Calendar.TUESDAY == dayOfWeek) { weekDayName = "Selasa"; } else if (Calendar.WEDNESDAY == dayOfWeek) { weekDayName = "Rabu"; } else if (Calendar.THURSDAY == dayOfWeek) { weekDayName = "Kamis"; } else if (Calendar.FRIDAY == dayOfWeek) { weekDayName = "Jumat"; } else if (Calendar.SATURDAY == dayOfWeek) { weekDayName = "Sabtu"; } else if (Calendar.SUNDAY == dayOfWeek) { weekDayName = "Minggu"; } return weekDayName; }
From source file:Main.java
public static String formatMediumDate(Context context, Calendar date) { return getAbbrevDayOfWeekString(date.get(Calendar.DAY_OF_WEEK)) + ", " + DateUtils.formatDateTime(context, date.getTimeInMillis(), DateUtils.FORMAT_NUMERIC_DATE); }
From source file:Main.java
private static Date getStartWeekOfMonth(int year, int month) { Calendar c = Calendar.getInstance(); c.set(year, month - 1, 1);/* w w w.j ava 2 s. c o m*/ int week = c.get(Calendar.DAY_OF_WEEK); return getDistanceDate(c.getTime(), 1 - week); }
From source file:Main.java
public static int getDayNum(int index) { java.util.Calendar calendar = new java.util.GregorianCalendar(); calendar.add(Calendar.DATE, index);// int dWeek = calendar.get(Calendar.DAY_OF_WEEK); int realDay = (dWeek - 1) == 0 ? 7 : (dWeek - 1); return realDay; }
From source file:Main.java
public static int getDayOfWeek() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); return cal.get(Calendar.DAY_OF_WEEK) - 1; }
From source file:DateUtils.java
public static Date getLastWeek() { GregorianCalendar dayBeforeThisWeek = new GregorianCalendar(); int dayFromMonday = (dayBeforeThisWeek.get(Calendar.DAY_OF_WEEK) + 7 - Calendar.MONDAY) % 7; dayBeforeThisWeek.add(Calendar.DATE, -dayFromMonday - 1); return dayBeforeThisWeek.getTime(); }
From source file:Main.java
public static int getWeekdayOfFirstDayOfMonth(int year, int month) { int dayOfWeek = -1; Calendar cal = Calendar.getInstance(); cal.set(year, month - 1, 1);// w w w . j a va 2s . c o m dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); return dayOfWeek - 1; }
From source file:Main.java
public static int getWeekOfDate(Date dt) { Calendar cal = Calendar.getInstance(); cal.setTime(dt);//www . j a v a2 s . c o m int w = cal.get(Calendar.DAY_OF_WEEK) - 1; if (w < 0) w = 0; return w; }
From source file:Main.java
public static Date getNextMonday(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from w w w . ja va 2s .c o m while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { cal.add(Calendar.DAY_OF_WEEK, 1); } return cal.getTime(); }