久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何找到給定月份的周六和周日?

How can I find Saturdays and Sundays in A given month?(如何找到給定月份的周六和周日?)
本文介紹了如何找到給定月份的周六和周日?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我想找到給定月份的所有周六和周日.我該怎么做?

I want find all Saturdays and Sundays in A given month. How can I do so?

推薦答案

最簡(jiǎn)單的方法是遍歷一個(gè)月中的所有日子,并檢查每個(gè)日子的星期幾.例如:

The simplest way is to just iterate over all the days in the month, and check the day of week for each of them. For example:

// This takes a 1-based month, e.g. January=1. If you want to use a 0-based
// month, remove the "- 1" later on.
public int countWeekendDays(int year, int month) {
    Calendar calendar = Calendar.getInstance();
    // Note that month is 0-based in calendar, bizarrely.
    calendar.set(year, month - 1, 1);
    int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

    int count = 0;
    for (int day = 1; day <= daysInMonth; day++) {
        calendar.set(year, month - 1, day);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == Calendar.SUNDAY || dayOfweek == Calendar.SATURDAY) {
            count++;
            // Or do whatever you need to with the result.
        }
    }
    return count;
}

絕對(duì)肯定有更有效的方法來(lái)做到這一點(diǎn) - 但這是我要開(kāi)始的,當(dāng)我發(fā)現(xiàn)它太慢時(shí)進(jìn)行優(yōu)化.

I'm absolutely sure there are far more efficient ways of doing this - but that's what I'd start with, and optimize when I'd found it's too slow.

請(qǐng)注意,如果您能夠使用 Joda Time,您的生活會(huì)輕松很多...

Note that if you're able to use Joda Time that would make your life a lot easier...

這篇關(guān)于如何找到給定月份的周六和周日?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 亚洲色综合 | 成人av激情 | 337p日本欧洲亚洲大胆精蜜臀 | 午夜精品福利视频 | 午夜电影福利 | 午夜影院视频在线观看 | 久久日韩粉嫩一区二区三区 | 亚洲人人舔人人 | 精品一区二区三区四区五区 | 欧美成人高清 | www.久草.com| 国产精品视频一区二区三区不卡 | 丁香六月伊人 | 日韩av美女电影 | 成人国产精品免费观看视频 | 国产视频第一页 | 中文字幕在线剧情 | 毛片在线看片 | 中文字幕国产第一页 | 午夜视频网站 | 亚州精品天堂中文字幕 | 亚洲综合无码一区二区 | 欧美一区二区三区四区视频 | 中文字幕在线一区二区三区 | 91视频在线观看 | 黄色片视频免费 | 国产高清视频一区 | 国产精品99久久久久久宅男 | 久久成| 国产亚洲精品综合一区 | 成人黄色av网址 | 欧美日韩国产一区二区三区 | 91精品成人久久 | 亚洲电影免费 | 国产98色在线 | 日韩 | 在线a视频网站 | 精品乱码一区二区三四区视频 | 日本一本视频 | 久久久999免费视频 999久久久久久久久6666 | 黄网站免费观看 | 国产区在线观看 |