Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get very short week day names in Android like Google Calendar app

I am finding a solution to get very short week day names like Google Calendar App.

The below is what I tried:

String[] shortWeekDays = DateFormatSymbols.getInstance(Locale.getDefault()).getShortWeekdays();

The result is

Sun, Mon, Tue, Wed, Thu, Fri, Sat

Google Calendar (Very short week-day names)

S, M, T, W, T, F, S

I like to use Week-day names like Google calendar

Updated I was thinking about getting first letter of week-day names (after DateFormatSymbols.getShortWeekdays) BUT for some languages (Chinese, Singapore, Taiwan), the first letter are the same for all 7 week-days. See my below test

String[] weekDays = DateFormatSymbols.getInstance(Locale.CHINESE).getShortWeekdays();

// 星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六]

I am thinking about using String resources BUT my application support all languages around the world based on current locale used, it is hard for me to put all very short week-day names for All languages.

Anyone has ideas? Thank you!

like image 236
Loc Avatar asked Aug 31 '25 17:08

Loc


2 Answers

After reviewed all locale available in Java and check their short week day names. I have my solution as below. It may help the others

  1. For Locale: China-chinese, Singapore-Chinese, Taiwan-Chinese

    • I will use String resources to store very short week day names because these locales return the same first letter for all their 7 week days.
  2. For the rest Locales

    • Use API that Java already provides: DateFormatSymbols.getShortWeekdays
    • Then get the first letter (or first two letters)
like image 80
Loc Avatar answered Sep 02 '25 07:09

Loc


The only solution I've seen for a one-character abbreviation for localized day names is the following:

DateUtils.getDayOfWeekString(dayOfWeek, DateUtils.LENGTH_SHORTEST)

Using DateFormatSymbols.getShortWeekdays and then pulling characters off the front doesn't work in other locales. For instance in Arabic, doing that results in the same character for every single day of the week.

like image 40
jacoballenwood Avatar answered Sep 02 '25 06:09

jacoballenwood