Java Date Start getStartDate(String date)

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

Description

get Start Date

License

Open Source License

Declaration

public static String getStartDate(String date) 

Method Source Code


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

public class Main {
    public static String getStartDate(String date) {
        String startDate;/*from w w  w  . j  a v a 2s  .  c  o m*/

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

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

        int startTmp = 1 - curDayOfWeek;

        Calendar tmpCalendar = Calendar.getInstance();

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

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

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

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

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

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

        return startDate;

    }

    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. getStart(Date date)
  2. getStartDate(Date date)
  3. getStartDate(Date date)
  4. getStartDate(Date date)
  5. getStartDateOfCurrentSemester()
  6. getStartDateOfCurrMonth()
  7. getStartDay(Date date)
  8. getStartDayOfNextMonth(Date date)