如何使用java8 time API获得一个月的两个特定日期之间的所有周末? [英] How to get all weekend between two specific day of month using java8 time API?

查看:188
本文介绍了如何使用java8 time API获得一个月的两个特定日期之间的所有周末?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用java8 time api在一个月的两个特定日期之间(例如从2018-10-26到2018-11-27)获得整个周末.该怎么做?

I want to get all weekend between two specific day of month (e.g. from 2018-10-26 to 2018-11-27) using java8 time api. How to do that?

推荐答案

尝试使用此功能,它将从您的时间获取所有星期六和星期日

Try this function, it will get all Saturday and Sunday from your Time

LocalDate startDate = LocalDate.of(2018, 10, 26);
LocalDate endDate = LocalDate.of(2018, 11, 27);
while (startDate.isBefore(endDate)) {
    if (startDate.getDayOfWeek().equals(DayOfWeek.SATURDAY) || startDate.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
        System.out.println(startDate + ":" + startDate.getDayOfWeek());
    }
    startDate = startDate.plusDays(1);
}

这篇关于如何使用java8 time API获得一个月的两个特定日期之间的所有周末?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆