List of usage examples for java.util Calendar MONDAY
int MONDAY
To view the source code for java.util Calendar MONDAY.
Click Source Link
From source file:Main.java
public static String getFirstDayOfWeek(String format) { return getDayOfWeek(format, Calendar.MONDAY); }
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++;// w ww . ja v a 2s. co m } cal.add(Calendar.DAY_OF_WEEK, -1); } return cal.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 int getWeekOfYear(Date date) { Calendar c = Calendar.getInstance(); c.setFirstDayOfWeek(Calendar.MONDAY); c.setTime(date);//from ww w . j a v a 2s .c om int week = c.get(Calendar.WEEK_OF_YEAR) - 1; week = week == 0 ? 52 : week; return week > 0 ? week : 1; }
From source file:Main.java
private static Date getNextBus(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//w ww.j av a 2s . c o m if (cal.get(Calendar.DAY_OF_WEEK) >= Calendar.MONDAY && cal.get(Calendar.DAY_OF_WEEK) <= Calendar.THURSDAY) { if (isBefore(cal, mon_thu[mon_thu.length - 1])) { setTime(cal, findNext(cal, mon_thu)); } else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) { setTime(cal, fri[0]); cal.add(Calendar.DAY_OF_YEAR, 1); } else { setTime(cal, mon_thu[0]); cal.add(Calendar.DAY_OF_YEAR, 1); } } else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) { if (isBefore(cal, fri[fri.length - 1])) { setTime(cal, findNext(cal, fri)); } else { setTime(cal, mon_thu[0]); cal.add(Calendar.DAY_OF_YEAR, 3); } } else { setTime(cal, mon_thu[0]); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); } return cal.getTime(); }
From source file:Main.java
public static Calendar calendar() { Calendar cal = GregorianCalendar.getInstance(Locale.CHINESE); cal.setFirstDayOfWeek(Calendar.MONDAY); return cal;/*from w w w . j ava 2 s. co m*/ }
From source file:Main.java
public static List<String> getWeekDate() { List<String> list = new ArrayList<String>(); Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.setTime(new Date()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); list.add(calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE)); for (int i = 0; i < 6; i++) { calendar.add(Calendar.DATE, 1); String str = calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE); list.add(str);/*from w w w . ja v a2 s . com*/ } return list; }
From source file:Main.java
public static int getDayOfWeek(Date date, int defSunday) { Calendar c = Calendar.getInstance(); c.setTime(date);/*from w w w.j a v a2 s . c o m*/ int day = c.get(Calendar.DAY_OF_WEEK); switch (day) { case Calendar.MONDAY: return 1; case Calendar.TUESDAY: return 2; case Calendar.WEDNESDAY: return 3; case Calendar.THURSDAY: return 4; case Calendar.FRIDAY: return 5; case Calendar.SATURDAY: return 6; case Calendar.SUNDAY: return defSunday; default: return 0; } }
From source file:Main.java
public static int compareDate(Calendar time1, Calendar time2) { int result = -1; if (time1.getTimeInMillis() == time2.getTimeInMillis()) { result = 0;//from w ww . j av a 2 s . com } else if (time1.get(Calendar.YEAR) == time2.get(Calendar.YEAR)) { result = 6; if (time1.get(Calendar.MONTH) == time2.get(Calendar.MONDAY)) { result = 5; if (time1.get(Calendar.DAY_OF_MONTH) == time2.get(Calendar.DAY_OF_MONTH)) { result = 4; if (time1.get(Calendar.HOUR_OF_DAY) == time2.get(Calendar.HOUR_OF_DAY)) { result = 3; if (time1.get(Calendar.MINUTE) == time2.get(Calendar.MINUTE)) { result = 2; if (time1.get(Calendar.SECOND) == time2.get(Calendar.SECOND)) { result = 1; } } } } } } else if (time1.get(Calendar.YEAR) / 100 == time2.get(Calendar.YEAR) / 100) { result = 7; } return result; }
From source file:Main.java
/** * Get first day of week as android.text.format.Time constant. * * @return the first day of week in android.text.format.Time *///from ww w.j a v a 2 s. co m public static int getFirstDayOfWeek(Context context) { int startDay = Calendar.SUNDAY; if (startDay == Calendar.SATURDAY) { return Time.SATURDAY; } else if (startDay == Calendar.MONDAY) { return Time.MONDAY; } else { return Time.SUNDAY; } }