Java Utililty Methods Week

List of utility methods to do Week

Description

The list of methods to do Week are organized into topic(s).

Method

StringgetWeek()
get Week
Calendar cal = Calendar.getInstance();
String week = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
return week;
StringgetWeek()
get Week
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-'W'ww-F");
return dateFormat.format(new Date());
Date[]getWeek(Date date)
get Week
Date[] dates = new Date[7];
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
for (int i = 0; i < 7; i++) {
    dates[i] = calendar.getTime();
    calendar.add(Calendar.DAY_OF_YEAR, 1);
...
intgetWeek(int duration)
This method subtracts the @param int duration that represents the weeks that past from the current week, and obtains the corresponding week of year.
Calendar cal_date = new GregorianCalendar();
DateFormat df = DateFormat.getInstance();
int kalwoch = 0;
cal_date.add(Calendar.WEEK_OF_YEAR, -duration);
kalwoch = cal_date.get(Calendar.WEEK_OF_YEAR);
return kalwoch;
intgetWeek(SimpleDateFormat df, String dateStr)
get Week
Calendar c = Calendar.getInstance();
try {
    c.setTime(df.parse(dateStr));
} catch (ParseException e) {
    e.printStackTrace();
int week = c.get(Calendar.DAY_OF_WEEK) - 1;
if (0 == week) {
...
StringgetWeek(String date)
get Week
Date dates = null;
String week = null;
try {
    dates = new SimpleDateFormat(_DEFAULT1).parse(date);
    week = formatDate(dates, _DEFAULT_CN_WEEK1);
} catch (ParseException e) {
    e.printStackTrace();
return week;
intgetWeek(String pTime)
get Week
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(format.parse(pTime));
int dayForWeek = 0;
if (c.get(Calendar.DAY_OF_WEEK) == 1) {
    dayForWeek = 7;
} else {
    dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
...
DategetWeekAgo()
get Week Ago
Date date = new Date();
long time = date.getTime() / 1000L - 604800L;
date.setTime(time * 1000L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
    date = format.parse(format.format(date));
} catch (Exception ex) {
    System.out.println(ex.getMessage());
...
DategetWeekBegin(Date date)
get Week Begin
return getWeekBegin(date, 0);
ListgetWeekDates(int weekOffset)
get Week Dates
return getWeekDates(weekOffset, "yyyy-MM-dd");