Skip to content

Get localized name of each day over next seven days using Android Studio

I should make this calendar of the week with different types of orders to be shown numerically depending on the data I receive. Do you have any idea how I could do this? for java code i should use material or native libraries

https://i.ibb.co/LvbgW4T/Immagine-2022-03-28-090511.jpg

Answer

tl;dr

Example code, not for production use.

LocalDate
.now()
.datesUntil( LocalDate.now().plusWeeks( 1 ) )
.map( localDate -> localDate.getDayOfWeek().getDisplayName( TextStyle.FULL , Locale.TAIWAN ) 
.toList() 

(In real work, never call now twice. At the end of the day, you may get two different values.)

Details

Per your Comment, you are asking how to list the next seven days of the week, localized.

Capture the current date. This requires a time zone, as the date varies around the globe by zone.

ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;
LocalDate today = LocalDate.now( z ) ;

Loop seven days, incrementing the date. Interrogate each date for its day-of-week. Get the localized name of that day.

Locale locale = Locale.CANADA_FRENCH ;
for( int index = 0 ; index < 7 ; index ++ ) 
{
    LocalDate ld = today.plusDays( index ) ;
    DayOfWeek dow = ld.getDayOfWeek() ;
    String dowName = dow.getDisplayName( TextStyle.FULL_STANDALONE , locale ) ;
    System.out.println ( dowName ) ;
}

This has been covered many times already on Stack Overflow. Search to learn more.