如何使用周数获​​得一周中的所有日子

时间:2014-01-16 09:22:32

标签: android calendar weekday

我很困惑,这件事。实际上我已经开发了一个视图寻呼机,它每周都会显示数据。我的意思是第一个屏幕是一年中的当前周,以及它的相关日期。然后我现在刷下我想要的下一个星期和它的日期。

即。目前,如果当前日期是2014/01/16,则当前周数为03.但是现在当我刷屏幕时,我想要1月的第04周日期。

提前致谢。

1 个答案:

答案 0 :(得分:1)

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

并且还尊敬

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