6

我正在尝试从给定日期获取当前周数。即,如果我输入日期为 01/03/2013,那么我应该得到周数,即 9..

请帮助我找到解决方案..

谢谢..

阿布舍克..

4

5 回答 5

15

您可以为该日期创建一个日历对象并使用 calendar.get(Calendar.WEEK_OF_YEAR) 获取星期。此处描述了 API:http: //developer.android.com/reference/java/util/Calendar.html#WEEK_OF_YEAR

于 2013-03-01T09:46:31.363 回答
11
    Calendar calender = Calendar.getInstance();
    Log.d("Current Week:" + calender.get(Calendar.WEEK_OF_YEAR));
于 2013-03-01T10:09:03.737 回答
4
Calendar sDateCalendar = new GregorianCalendar(2013,03,01);
Calendar.getInstance().get(Calendar.WEEK_OF_YEAR);
于 2013-03-01T09:47:07.740 回答
1

01/03/2013 记为 113 , 2 ,1

            Date d = new Date(113, 2, 1);

            Calendar c = Calendar.getInstance();

            c.setTime(d);

            int weekOfYear = c.get(Calendar.WEEK_OF_YEAR);
于 2014-01-30T07:17:37.623 回答
0

日历日历 = Calendar.getInstance(); Log.d("当前周:" + calender.get(Calendar.WEEK_OF_YEAR));

于 2015-05-07T08:43:21.947 回答