Android:如何以用户的语言获取当前的星期几(星期一等)?

我想知道当前的星期几(星期一、星期二...),用用户的本地语言表示.例如,Lundi"狂欢"等等...如果用户是法国人.

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.

我已经阅读了这篇文章,但它只返回一个整数,而不是用户语言的日期字符串:在 Android 中获取当前星期几的最简单方法是什么?

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 ?

我认为这是可能的,例如,Google 议程以用户的当地语言给出了日期和月份.

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

推荐答案

使用 SimpleDateFormat 来根据用户的区域设置,将日期和时间格式化为人类可读的字符串.

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);

相关文章