gpt4 book ai didi

java - 考虑到 Java 中的当前语言环境,如何检查某个日期是否为周末?

转载 作者:搜寻专家 更新时间:2023-11-01 03:24:39 26 4
gpt4 key购买 nike

我正在用 Java 编写程序,我需要确定某个日期是否是周末。然而,我需要考虑到在不同的国家周末是在不同的日子,例如在以色列是周五和周六,而在一些伊斯兰国家是周四和周五。更多详情可以查看this Wikipedia article .有简单的方法吗?

最佳答案

根据您发送的 wiki,我使用以下代码自行解决了该问题:

private static final List<String> sunWeekendDaysCountries = Arrays.asList(new String[]{"GQ", "IN", "TH", "UG"});
private static final List<String> fryWeekendDaysCountries = Arrays.asList(new String[]{"DJ", "IR"});
private static final List<String> frySunWeekendDaysCountries = Arrays.asList(new String[]{"BN"});
private static final List<String> thuFryWeekendDaysCountries = Arrays.asList(new String[]{"AF"});
private static final List<String> frySatWeekendDaysCountries = Arrays.asList(new String[]{"AE", "DZ", "BH", "BD", "EG", "IQ", "IL", "JO", "KW", "LY", "MV", "MR", "OM", "PS", "QA", "SA", "SD", "SY", "YE"});

public static int[] getWeekendDays(Locale locale) {
if (thuFryWeekendDaysCountries.contains(locale.getCountry())) {
return new int[]{Calendar.THURSDAY, Calendar.FRIDAY};
}
else if (frySunWeekendDaysCountries.contains(locale.getCountry())) {
return new int[]{Calendar.FRIDAY, Calendar.SUNDAY};
}
else if (fryWeekendDaysCountries.contains(locale.getCountry())) {
return new int[]{Calendar.FRIDAY};
}
else if (sunWeekendDaysCountries.contains(locale.getCountry())) {
return new int[]{Calendar.SUNDAY};
}
else if (frySatWeekendDaysCountries.contains(locale.getCountry())) {
return new int[]{Calendar.FRIDAY, Calendar.SATURDAY};
}
else {
return new int[]{Calendar.SATURDAY, Calendar.SUNDAY};
}
}

关于java - 考虑到 Java 中的当前语言环境,如何检查某个日期是否为周末?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17927854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com