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

StringgetWeekFirst(String format)
get Week First
Calendar c = Calendar.getInstance();
int days = getDayInWeek();
c.add(GregorianCalendar.DATE, 2 - ((days == 1) ? 8 : days));
SimpleDateFormat sf = new SimpleDateFormat(format);
return sf.format(c.getTime());
StringgetWeekFromDate(String dateString)
get Week From Date
StringBuffer sb = new StringBuffer();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
    Date date = format.parse(dateString);
    Date mondy = new Date();
    Date sundy = new Date();
    int day = date.getDay();
    if (day == 0) {
...
IntegergetWeekId(String date)
get Week Id
Date d = new Date();
try {
    d = yyyyMMdd.parse(date);
} catch (ParseException e) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(d);
Integer i = calendar.get(Calendar.DAY_OF_WEEK) - 1;
...
intgetWeekInMonth()
get Week In Month
Calendar c = Calendar.getInstance();
int week = c.get(Calendar.WEEK_OF_MONTH);
return week;
StringgetWeekName()
get Week Name
return getCurrentTime("yyyy") + getWeekOfYear();
intgetWeekNumber(String sdate)
get Week Number
Date date = strToDate(sdate);
Calendar c = Calendar.getInstance();
c.setTime(date);
return c.get(Calendar.DAY_OF_WEEK);
StringgetWeekNumberFromDate(String thedate)
get Week Number From Date
String strReturn = "";
SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String dateStringToParse = thedate;
try {
    Date date = bartDateFormat.parse(dateStringToParse);
    SimpleDateFormat bartDateFormat2 = new SimpleDateFormat("yyyy-MM-dd EEEE");
    strReturn = bartDateFormat2.format(date);
} catch (Exception ex) {
...
intgetWeekNumByDate(String date)
get Week Num By Date
SimpleDateFormat format = new SimpleDateFormat(DF_YMD);
try {
    Date d = format.parse(date);
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    int num = cal.get(Calendar.DAY_OF_WEEK) - 1;
    return num;
} catch (ParseException e) {
...
IntegergetWeekNumner(String date)
get Week Numner
Integer weekNumber = 0;
try {
    if (date.equals("")) {
        return weekNumber;
    DateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
    Date passedDate = formatter.parse(date);
    Calendar cal = Calendar.getInstance();
...
intgetWeekOfMonth()
Used to know what week of the month it is to display a different image on the main page
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.WEEK_OF_MONTH);