Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get one letter abbreviation of week day of a date in java

As far I know, in Java I can get weekdays in normal (Friday) or short mode (Fri). But, there is any way to obtain only first letter?

I thought I can get first letter using "substring", but it won't be correct for all languages. For example, spanish weekdays are: Lunes, Martes, Miércoles, Jueves, Viernes, Sábado and Domingo, and first letter for "Miércoles" is X instead of M to difference it from "Martes".

like image 428
Sergio Viudes Avatar asked Jun 06 '13 10:06

Sergio Viudes


People also ask

What time format code will display the name of the day?

Format dateFormat = new SimpleDateFormat("EEE, dd/MM/yyyy"); Above, the “EEE” is set to display the name of the day i.e. Monday, Tuesday, Wednesday, etc.

How do I display the day of the week in Android?

SimpleDateFormat sdf_ = new SimpleDateFormat("EEEE"); Date date = new Date(); String dayName = sdf_. format(date); timeUpdate. setText("" + dayName + " " + currentDate + "");


1 Answers

In Android you can use SimpleDateFormat with "EEEEE". In the next example you can see it.

SimpleDateFormat formatLetterDay = new SimpleDateFormat("EEEEE",Locale.getDefault());
String letter = formatLetterDay.format(new Date());
like image 133
Husky Avatar answered Nov 02 '22 19:11

Husky