How to calculate week number for given date Android

廉价感情. 提交于 2019-12-12 08:05:42

问题


I am trying to get the the current week number from the given date. i.e. If I enter the date as 01/03/2013 then i should get the week number which is 9..

Please help me in finding the solution..

Thanks..

Abhishek..


回答1:


You can create a Calendar object for that date and get the week with calendar.get(Calendar. WEEK_OF_YEAR). The API is described here: http://developer.android.com/reference/java/util/Calendar.html#WEEK_OF_YEAR




回答2:


    Calendar calender = Calendar.getInstance();
    Log.d("Current Week:" + calender.get(Calendar.WEEK_OF_YEAR));



回答3:


Calendar sDateCalendar = new GregorianCalendar(2013,03,01);
Calendar.getInstance().get(Calendar.WEEK_OF_YEAR);



回答4:


01/03/2013 is taken in as 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);



回答5:


Calendar calender = Calendar.getInstance(); Log.d("Current Week:" + calender.get(Calendar.WEEK_OF_YEAR));



来源:https://stackoverflow.com/questions/15154673/how-to-calculate-week-number-for-given-date-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!