Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java检查给定日期是否不是周末、月底和季度末_Java_Jodatime - Fatal编程技术网

如何使用java检查给定日期是否不是周末、月底和季度末

如何使用java检查给定日期是否不是周末、月底和季度末,java,jodatime,Java,Jodatime,如何检查给定日期是否不是周末、月末和 季度末 不应该是周末、月底和季度末 对于周末,您可以使用: DateTime dt = new DateTime(ts*1000l, DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT"))); Integer newTs = (int) (dt.withDayOfWeek(DateTimeConstants.SUNDAY).getMillis()/1000); if(newTs == ts){ //

如何检查给定日期是否不是周末、月末和 季度末

不应该是周末、月底和季度末


对于周末,您可以使用:

DateTime dt = new DateTime(ts*1000l, DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT")));

Integer newTs = (int) (dt.withDayOfWeek(DateTimeConstants.SUNDAY).getMillis()/1000);

if(newTs == ts){
  // it's end of the week
}
使用lib,其中
ts
是您的时间戳(int),类似地,您可以使用
withDayOfMonth
检查是否是月末。

这里有一个部分答案:

LocalDate today = LocalDate.now();
LocalDate endOfMonth = today.dayOfMonth().withMaximumValue();
System.out.println("Today is end of month: " + today.equals(endOfMonth));

请注意,类似的简单解决方案不可能用于季度,因为Joda Time不支持该元素(变通方法或其他必要的库)。此外,只要您希望ISO-8601兼容的日历周从周一开始,日历年内至少有4天(不包括我们的周),就可以使用
weekOfWeekyear()
而不是
dayOfMonth()
为日历周提供类似的解决方案.

显示日期不在月的最后一天来覆盖一年中的季度,这还不够吗?提示:
java.time.LocalDate
java.time.DayOfWeek
java.time.YearMonth
org.threeten.extra.YearWeek
org.threeten.extra.YearQuarter::atDay
::atEndOfQuarter
。我不知道你能用
LocalDate
这么容易找到月底