List of utility methods to do Week Day
long | getLastWeekMs() get Last Week Ms return new Date().getTime() - 7 * 24 * 60 * 60 * 1000; |
String | getMon() get Mon Date date = Calendar.getInstance().getTime(); String sDate = convDateToString(date, "MM"); return sDate; |
String | getMonday(String date) get Monday SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMdd"); Date d = null; try { d = format.parse(date); } catch (Exception e) { e.printStackTrace(); Calendar cal = Calendar.getInstance(); cal.setTime(d); int days = cal.get(Calendar.DAY_OF_WEEK); if (days == 1) { days = 1; String preMonday = getPreviousMonday(d, days); System.out.println("preMonday" + preMonday); return preMonday; } else { cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return format2.format(cal.getTime()); |
Date | getMonday(String date, int weekDay) get Monday SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date d = null; try { d = format.parse(date); } catch (Exception e) { e.printStackTrace(); Calendar cal = Calendar.getInstance(); ... |
Date | getMondayAfter(Date date) get Monday After Calendar cal = Calendar.getInstance(); cal.setTime(date); while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { cal.add(Calendar.DATE, 1); return cal.getTime(); |
String | getMondayOfThisWeek() get Monday Of This Week Calendar c = Calendar.getInstance(); int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; if (day_of_week == 0) day_of_week = 7; c.add(Calendar.DATE, -day_of_week + 1); return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); |
int | getNextDayOfweek() get Next Day Ofweek Calendar calendar = Calendar.getInstance(); calendar.setTime(new java.util.Date(date.getTime() + 24 * 60 * 60 * 1000)); if (calendar.get(Calendar.DAY_OF_WEEK) == 1) return 7; else return calendar.get(Calendar.DAY_OF_WEEK) - 1; |
String | getPreDay() get Pre Day Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_WEEK, -1); Date preTime = calendar.getTime(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); return formatter.format(preTime); |
long | getPreviousDay(long date, int startOfWeek) Returns the first day before date that has the day of week matching startOfWeek .
return getDay(date, startOfWeek, -1);
|
String | getPreviousFriday(String date) get Previous Friday Date d = strToDtSimpleFormat(date);
Calendar cal = Calendar.getInstance();
cal.setTime(d);
cal.add(Calendar.WEEK_OF_YEAR, -1);
cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
return dateFormat(cal.getTime());
|