I'm working on an Android app where I need to display the days of the week from the calendar. Can I do that using the calendar API ? or there is a library that can I use ? Thanks
-
Display the days of the week, such as? Getting a date and showing the day of the week? – Ashley Alvarado Aug 11 '15 at 18:07
-
See similar Question, [Samsung J7 returning first day of week as 2](http://stackoverflow.com/q/40041147/642706). – Basil Bourque May 10 '17 at 02:51
-
This seems to be duplicate of: [(Android) Get first day of week](http://stackoverflow.com/q/25091904/642706) – Basil Bourque May 10 '17 at 03:15
4 Answers
For date handling in Android, I recommend 310ABP, a port of the Java 8 new date APIs for Android.

- 5,599
- 6
- 23
- 33
You could use the JodaTime library to display the current day of the week.
LocalDate newDate = new LocalDate();
int dayOfWeek = newDate.getDayOfWeek();

- 234
- 1
- 9
or there is a library that can I use ?
Yes. Use the back-port of the java.time classes. See "Android" item below.
Using java.time
LocalDate
The LocalDate
class represents a date-only value without time-of-day and without time zone.
A time zone is crucial in determining a date. For any given moment, the date varies around the globe by zone. For example, a few minutes after midnight in Paris France is a new day while still “yesterday” in Montréal Québec.
Specify a proper time zone name in the format of continent/region
, such as America/Montreal
, Africa/Casablanca
, or Pacific/Auckland
. Never use the 3-4 letter abbreviation such as EST
or IST
as they are not true time zones, not standardized, and not even unique(!).
ZoneId z = ZoneId.of( "America/Montreal" );
LocalDate today = LocalDate.now( z );
TemporalAdjuster
To get the first day of the week, (a) decide what is the first day of the week for you, (b) use a TemporalAdjuster
implementation defined in TemporalAdjusters
to get the date for a specific [DayOfWeek
][6] enum object.
LocalDate ld = today.with( TemporalAdjusters.previousOrSame( DayOfWeek.MONDAY ) ) ;
To get a week’s worth of dates, add a day at a time.
LocalDate localDate = ld ; // Initialize our looping variable.
List<LocalDate> dates = new ArrayList<>( 7 ) ;
for( int i = 0 , i < 7 , i ++ ) { // Loop seven times, to cover a week.
localDate = localDate.plusDays( i );
dates.add( localDate ) ;
}
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8, Java SE 9, and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and Java SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
- The ThreeTenABP project adapts ThreeTen-Backport (mentioned above) for Android specifically.
- See How to use ThreeTenABP….

- 1
- 1

- 303,325
- 100
- 852
- 1,154