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

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

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

問題描述

限時送ChatGPT賬號..

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

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

推薦答案

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

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;
}

絕對肯定有更有效的方法來做到這一點(diǎn) - 但這是我要開始的,當(dāng)我發(fā)現(xiàn)它太慢時進(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.

請注意,如果您能夠使用 Joda Time,您的生活會輕松很多...

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

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

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 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)前星期幾的值)
主站蜘蛛池模板: 日韩欧美国产精品 | 91精品久久久久久久久久入口 | 成人h电影在线观看 | 99精品网 | 亚洲精品欧洲 | 日韩和的一区二区 | 成人精品视频99在线观看免费 | 亚洲三区在线观看 | 中文字幕av网 | 国产精品久久久久免费 | av性色全交蜜桃成熟时 | 精品久久久久一区二区国产 | 狠狠狠色丁香婷婷综合久久五月 | 精品国产黄a∨片高清在线 成人区精品一区二区婷婷 日本一区二区视频 | 91精品国产综合久久精品 | 国产乱码精品一区二区三区忘忧草 | 午夜视频在线观看网址 | 欧美激情第一区 | av手机在线免费观看 | 色综合久久天天综合网 | 国产乱性 | 欧美精品国产一区二区 | 黄色免费av | 男人午夜视频 | 国产精品美女久久久久久不卡 | 亚洲精品日本 | 成人一区二区三区 | 99草免费视频 | 国产日韩欧美一区二区 | 日本一二三区在线观看 | 国产精品一区二区三区久久久 | 99re视频在线| 亚洲综合大片69999 | 日韩免费视频一区二区 | 干出白浆视频 | 一区二区在线不卡 | 中文字幕av一区 | 天天色天天色 | 日韩激情在线 | 日韩中文字幕在线观看 | 久久伊人精品一区二区三区 |