سؤال

I am confused a lot, by this thing. Actually I have developed one view pager, which is showing data week wise. I mean first screen is for current week of the year, and its related dates. Then now I swipe the screen I want next number of weeks and its dates.

i.e. For now, if current date is 2014/01/16 then current week number is 03. But now when I swipe the screen, I want 04th week dates of January.

Thanks in advance.

هل كانت مفيدة؟

المحلول

 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);
    }

and also reverese

Calendar now = Calendar.getInstance();


  now.set(Calendar.YEAR,2013);
  now.set(Calendar.MONTH,04);//0- january ..4-May
  now.set(Calendar.DATE, 04);

System.out.println("Current week of month is : " +
            now.get(Calendar.WEEK_OF_MONTH));

System.out.println("Current week of year is : " +
            now.get(Calendar.WEEK_OF_YEAR));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top