問題描述
我想知道當前的星期幾(星期一、星期二...),用用戶的本地語言表示.例如,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);
這篇關于Android:如何以用戶的語言獲取當前的星期幾(星期一等)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!