I want to divide a month based on number of weeks. For example, If current month is January and current date is 23-01-2020. Then it should show first week from 30-12 to 05-01, 06-01 to 12-01 and ... 20-01 to 23-01 so on. After get this i want to save these date into my list. Please help me to find out the better solution.
Asked
Active
Viewed 142 times
-1
-
Current month is Jan. Current date is 23rd. Why is the first week then decemeber? I don't get the relationship of you saying Jan 23rd, and then how you chose your weeks. – Blundell Jan 23 '20 at 09:57
-
maybe you can start with this https://stackoverflow.com/questions/7651221/android-how-to-get-the-current-day-of-the-week-monday-etc-in-the-users-l – Pablo R. Jan 23 '20 at 09:57
-
@Blundell Because 1 st of january start week is 30-12. And today date is 23 january. So this week stops at 23 – user2210356 Jan 23 '20 at 10:03
-
You just want to use week numbers which is very common and ready available under Android. And you did still not tell why -for you- 30-12 is the first day of the first week of this year. – blackapps Jan 23 '20 at 10:09
-
ok then please give me link how to do it. Ok from 1 st to 5 th is the first week. So how can i get it in string. – user2210356 Jan 23 '20 at 10:13
-
You can try a thirdparty library such as JodaTime or ThreetenBP – Rafsanjani Jan 23 '20 at 10:20
1 Answers
0
Hello Please try below code
cal.set(Calendar.YEAR, 2013);
cal.set(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, 1);
int start = cal.get(Calendar.WEEK_OF_YEAR);
Log.d("BLA BLA", "Value is " + start);
cal.set(Calendar.YEAR, 2013);
cal.set(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, 28);
int end = cal.get(Calendar.WEEK_OF_YEAR);
//Above line will not work for December Month, use following line for this
int end = isDecember?53:cal.get(Calendar.WEEK_OF_YEAR);
Log.d("BLA BLA", "Value is " + end);
Log.d("BLA BLA", "Num weeks:: " + (end - start +1 ));```

Ashok Songara
- 162
- 1
- 10