4

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!

LHA
  • 9,398
  • 8
  • 46
  • 85
  • What about something like this?http://stackoverflow.com/a/6789565/2823516 And then you can manipulate the String to get the substring you want – Joaquin Iurchuk Apr 15 '15 at 14:28
  • @joaquin: I took a look at that thread already but It didn't help. I can get short week day names as I said but I am looking for the way to get very short week day names (may be 1 character). Thanks! – LHA Apr 15 '15 at 14:30
  • Are you using the Java Locales mentioned on that answer? – Joaquin Iurchuk Apr 15 '15 at 14:32
  • Yes, I am using Java Locale & Java DateFormatSymbols. – LHA Apr 15 '15 at 14:33
  • I don't remember too well, but I think Locale.default was available. My app uses something like that and then I get the day name and then I substring it – Joaquin Iurchuk Apr 15 '15 at 14:34
  • you cannot substring, may work in english but won´t work for Spanish, for example because two days share the same character and we note the second one with an X even when it´s not used in the real name – eduyayo Apr 15 '15 at 14:36

3 Answers3

3

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)
LHA
  • 9,398
  • 8
  • 46
  • 85
1

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.

jacoballenwood
  • 2,787
  • 2
  • 24
  • 39
1
/**
* @param day Int
* @return short day name
* Calendar.MONDAY -> Mon
*/
fun getShortDayName(day: Int): String {
   val c = Calendar.getInstance()
   c.set(Calendar.DAY_OF_WEEK, day)
   return String.format("%ta", c)
}

For detailed Formatter short conversions Formatter

For getting only first letter you can use TextView maxLength=1 or getShortDayName(Calendar.TUESDAY)[0] //its will return 'T'

Community
  • 1
  • 1
murgupluoglu
  • 6,524
  • 4
  • 33
  • 43