Monday, September 28, 2020

Use DateFormatSymbols().getShortWeekday to convert the dayOfWeek of the calendar into Chinese form

 In android development, sometimes we need to convert the week information obtained from calendar.get(Calendar.DAY_OF_WEEK) into the column format of Chinese "Monday, Tuesday".

The common way is:

string [] Day=new string []{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

Day[dayofweek];

In fact, there is an easier way:

new DateFormatSymbols().getShortWeekdays()[calendar.get(Calendar.DAY_OF_WEEK)]

This method is multi-language support, and it will be automatically converted to the corresponding form when switching languages.




No comments:

Post a Comment