Java Day End getEndDate(String date)

Here you can find the source of getEndDate(String date)

Description

get End Date

License

Open Source License

Declaration

public static String getEndDate(String date) 

Method Source Code


//package com.java2s;
import java.util.Calendar;

public class Main {
    public static String getEndDate(String date) {
        String endDate;/*from ww w  .  jav a  2  s  . c  o  m*/

        int year = getYear(date);
        int month = getMonth(date);
        int day = getDate(date);

        int curDayOfWeek = getDayOfWeek(year, month, day);

        int endTmp = 7 - curDayOfWeek;

        Calendar tmpCalendar = Calendar.getInstance();

        tmpCalendar.set(year, month - 1, day);
        tmpCalendar.add(Calendar.DATE, endTmp);

        endDate = Integer.toString(tmpCalendar.get(Calendar.YEAR));

        if ((tmpCalendar.get(Calendar.MONTH) + 1) < 10)
            endDate += "0";

        endDate += Integer.toString((tmpCalendar.get(Calendar.MONTH)) + 1);

        if (tmpCalendar.get(Calendar.DATE) < 10)
            endDate += "0";

        endDate += Integer.toString(tmpCalendar.get(Calendar.DATE));

        return endDate;
    }

    public static int getYear(String date) {
        return Integer.parseInt(date.substring(0, 4));
    }

    public static int getMonth(String date) {
        return Integer.parseInt(date.substring(4, 6));
    }

    public static int getDate(String date) {
        return Integer.parseInt(date.substring(6, 8));
    }

    public static int getDayOfWeek(int _year, int _month, int _day) {
        int year, month, date;

        Calendar cal = Calendar.getInstance();
        cal.set(_year, _month - 1, _day);

        return cal.get(Calendar.DAY_OF_WEEK);
    }
}

Related

  1. getEndDate()
  2. getEndDate(Date beginDate, int resolution)
  3. getEndDate(Date date)
  4. getEndDate(Date startDate)
  5. getEndDate(int useMonth)
  6. getEndDateByDate(Date date)
  7. getEndDateByYears(Date date, int years)
  8. getEndDateForYear()
  9. getEndDateOfCurrentSemester()