本文介紹了如何獲得某個地區/國家/地區的第一天的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我需要獲取某個區域/國家/地區的一周的第一天.
I need to get the first day of week for a certain Locale / Country.
我嘗試使用以下代碼找到它:
I tried to find it using this code:
final Locale[] locales = new Locale[]{
new Locale("en_GB"),
new Locale("ru_RU"),
new Locale("en_US"),
new Locale("es_ES"),
new Locale("fr_FR"),
new Locale("iw_IL"),
new Locale("he_IL")
};
for (final Locale locale : locales) {
final Calendar cal = Calendar.getInstance(locale);
final int firstDayOfWeek = cal.getFirstDayOfWeek();
System.out.println(firstDayOfWeek);
}
這段代碼的結果是,所有這些語言環境都在檢索1",即星期日,而諸如 en_US
之類的語言環境應該返回 2,即星期一.
The result of this code is that all of these locales are retrieving '1' which is Sunday, and locales such en_US
should return 2 which is Monday.
推薦答案
傳入兩個參數 - language &國家/地區,分開 - 而不是你的帶下劃線的字符串.請參閱 Oracle 教程.
Pass in two arguments –?language & country, separately – rather than your string with underscore. See Oracle Tutorial.
final Locale[] locales = new Locale[]{
new Locale("en", "GB"), // Pass language code, then country code, separately.
new Locale("ru", "RU"),
new Locale("en", "US"),
new Locale("es", "ES"),
new Locale("fr", "FR"),
new Locale("iw", "IL"),
new Locale("he", "IL")
};
然后我會使用 Java8 來獲取一周的第一天:
And then I would use Java8 to get the first day of the week:
DayOfWeek firstDayOfWeek = WeekFields.of(locale).getFirstDayOfWeek();
System.out.println(firstDayOfWeek);
輸出:
星期一
星期一
星期天
星期一
星期一
星期天
星期天
這篇關于如何獲得某個地區/國家/地區的第一天的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!