在 Android 中,您可以将 SimpleDateFormat 与“EEEEE”一起使用。在下一个示例中您可以看到它。
SimpleDateFormat formatLetterDay = new SimpleDateFormat("EEEEE",Locale.getDefault());
String letter = formatLetterDay.format(new Date());
编辑:实际上并不完全正确。 Android 上的结果可能不止一个字母(而且也不是唯一的,如果这很重要的话),但这就是我们所拥有的。以下证据表明,在 Android 上遍历所有区域设置无法获得这些特征。它是用 Kotlin 编写的,但当然也应该适用于 Java:
val charCountStats = SparseIntArray()
Locale.getAvailableLocales().forEach { locale ->
val sb = StringBuilder("$locale : ")
val formatLetterDay = SimpleDateFormat("EEEEE", locale)
for (day in 1..7) {
val cal = Calendar.getInstance()
cal.set(Calendar.DAY_OF_WEEK, day)
val letter: String = formatLetterDay.format(cal.time)
charCountStats.put(letter.length, charCountStats.get(letter.length, 0)+1)
sb.append(letter)
if (day != 7)
sb.append(',')
}
Log.d("AppLog", "$sb")
}
Log.d("AppLog", "stats:")
charCountStats.forEach { key, value ->
Log.d("AppLog", "formatted days with $key characters:$value")
}
结果是,在大多数情况下,它确实是一个字母,但对于许多情况来说,它更多,甚至可以达到 8 个字符(尽管它可能看起来更少,甚至一个):
formatted days with 1 characters:4889
formatted days with 2 characters:471
formatted days with 3 characters:99
formatted days with 4 characters:58
formatted days with 5 characters:3
formatted days with 8 characters:3
显示为 3 个字母(而不仅仅是 3 个字母)的区域设置示例是“wo”(“Wolof”语言),因为这是使用上述格式的一周中每一天的结果:
Dib,Alt,Tal,Àla,Alx,Àjj,Ase