android - In Java, how to get strings of days of week (Sun, Mon, ..., Sat) with system's default Locale (language) -
the simplest way:
string[] namesofdays = new string[7] { "sun", "mon", "tue", "wed", "thu", "fri", "sat" }; this method not use locale. therefore, if system's language not english, method not work properly.
using joda time, can this:
string[] namesofdays = new string[7]; localdate = new localdate(); (int i=0; i<7; i++) { /* datetimeconstants.monday = 1, tuesday = 2, ..., sunday = 7 */ namesofdays[i] = now.withdayofweek((datetimeconstants.sunday + - 1) % 7 + 1) .dayofweek().getasshorttext(); } however, method uses today's date , calendar calculations, useless final purpose. also, little complicated.
is there easy way strings sun, mon, ..., sat system's default locale?
if have not misunderstood you
calendar.getdisplayname(calendar.day_of_week, calendar.short, locale.us); is looking for. here can find documentation,
or can use, getshortweekdays()
string[] namesofdays = dateformatsymbols.getinstance().getshortweekdays()
Comments
Post a Comment