Java Year Get getStartEndOFWeek(int enterWeek, int enterYear)

Here you can find the source of getStartEndOFWeek(int enterWeek, int enterYear)

Description

Return the date of start and end of the week

License

Open Source License

Parameter

Parameter Description
enterWeek Number of the week in the year
enterYear year

Return

Return string in format "yyyy.mm.dd - yyyy.mm.dd"

Declaration

public static String getStartEndOFWeek(int enterWeek, int enterYear) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**//from  ww w . j  a v  a  2 s  .c  om
     * Return the date of start and end of the week
     * @param enterWeek Number of the week in the year
     * @param enterYear year
     * @return Return string in format "yyyy.mm.dd - yyyy.mm.dd"
     */
    public static String getStartEndOFWeek(int enterWeek, int enterYear) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.WEEK_OF_YEAR, enterWeek);
        calendar.set(Calendar.YEAR, enterYear);

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd"); // PST`
        Date startDate = calendar.getTime();
        String startDateInStr = formatter.format(startDate);

        calendar.add(Calendar.DATE, 6);
        Date enddate = calendar.getTime();
        String endDaString = formatter.format(enddate);

        return startDateInStr + " - " + endDaString;
    }
}

Related

  1. getNextYearFirst()
  2. getNextYearMonthStr()
  3. getOfflimitDates(int year)
  4. getRandomDate(int firstYar, int lastYear)
  5. getSpecficYearEnd(Date date, int amount)
  6. getStartOfYear()
  7. getThisYear()
  8. getThisYear()
  9. getThisYear()