Android: how to get the current day of the week (Monday, etc...) in the user's language?

Regis_AG picture Regis_AG · Oct 4, 2011 · Viewed 121.1k times · Source

I want to know what the current day of the week is (Monday, Tuesday...) in the user's local language. For example, "Lundi" "Mardi" etc... if the user is French.

I have read this post, it but it only returns an int, not a string with the day in the user's language: What is the easiest way to get the current day of the week in Android?

More generally, how do you get all the days of the week and all the months of the year written in the user's language ?

I think that this is possible, as for example the Google agenda gives the days and months written in the user's local language.

Thanks !!

Answer

user658042 picture user658042 · Oct 4, 2011

Use SimpleDateFormat to format dates and times into a human-readable string, with respect to the users locale.

Small example to get the current day of the week (e.g. "Monday"):

SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
Date d = new Date();
String dayOfTheWeek = sdf.format(d);