获得一周的开始和周数和放结束日期;今年的android日期、结束、今年、android

2023-09-06 02:52:49 作者:聋子听哑巴说瞎子见过爱

我希望得到的起始日期和放大器;一周的结束日期,传递给该方法的周数。例如,如果我通过周数为 51 并在今年为 2011 ,它应该回到我开始日期 2011年12月18日和结束日期为 2011年12月24日

I wish to get the start date & end date of the week, for a week number passed in to the method. For example, if i pass the week number as 51 and the year as 2011, it should return me start date as 18 Dec 2011 and the end date as 24 Dec 2011

有没有这将有助于我实现这一目标的方法?

Are there any methods that will help me achieve this?

推荐答案

您可以使用下面的方法来获得一个星期的第一日期和结束日期

You can use the following method to get first date and end date of a week

 void getStartEndOFWeek(int enterWeek, int enterYear){
//enterWeek is week number
//enterYear is year
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.WEEK_OF_YEAR, enterWeek);
        calendar.set(Calendar.YEAR, enterYear);

        SimpleDateFormat formatter = new SimpleDateFormat("ddMMM yyyy"); // PST`
        Date startDate = calendar.getTime();
        String startDateInStr = formatter.format(startDate);
        System.out.println("...date..."+startDateInStr);

        calendar.add(Calendar.DATE, 6);
        Date enddate = calendar.getTime();
        String endDaString = formatter.format(enddate);
        System.out.println("...date..."+endDaString);
    }