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

如何查看是否是周六/周日?

How to check if it#39;s Saturday/Sunday?(如何查看是否是周六/周日?)
本文介紹了如何查看是否是周六/周日?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

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

這段代碼的作用是打印本周從星期一到星期五的日期.它工作得很好,但我想問點(diǎn)別的:如果今天是周六或周日,我希望它在下周顯示.我該怎么做?

What this code does is print the dates of the current week from Monday to Friday. It works fine, but I want to ask something else: If today is Saturday or Sunday I want it to show the next week. How do I do that?

這是我目前的工作代碼(感謝 StackOverflow!):

Here's my working code so far (thanks to StackOverflow!!):

// Get calendar set to current date and time
Calendar c = Calendar.getInstance();

// Set the calendar to monday of the current week
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

// Print dates of the current week starting on Monday to Friday
DateFormat df = new SimpleDateFormat("EEE dd/MM/yyyy");
for (int i = 0; i <= 4; i++) {
    System.out.println(df.format(c.getTime()));
    c.add(Calendar.DATE, 1);
}

非常感謝!我真的很感激它,因?yàn)槲乙呀?jīng)尋找了幾個(gè)小時(shí)的解決方案......

Thanks a lot! I really appreciate it as I've been searching for the solution for hours...

推薦答案

public static void main(String[] args) {
    Calendar c = Calendar.getInstance();
    // Set the calendar to monday of the current week
    c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

    // Print dates of the current week starting on Monday to Friday
    DateFormat df = new SimpleDateFormat("EEE dd/MM/yyyy");
    for (int i = 0; i <= 10; i++) {
        System.out.println(df.format(c.getTime()));
        int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == Calendar.FRIDAY) { // If it's Friday so skip to Monday
            c.add(Calendar.DATE, 3);
        } else if (dayOfWeek == Calendar.SATURDAY) { // If it's Saturday skip to Monday
            c.add(Calendar.DATE, 2);
        } else {
            c.add(Calendar.DATE, 1);
        }

        // As Cute as a ZuZu pet.
        //c.add(Calendar.DATE, dayOfWeek > Calendar.THURSDAY ? (9 - dayOfWeek) : 1);
    }
}

輸出

Mon 03/01/2011
Tue 04/01/2011
Wed 05/01/2011
Thu 06/01/2011
Fri 07/01/2011
Mon 10/01/2011
Tue 11/01/2011
Wed 12/01/2011
Thu 13/01/2011
Fri 14/01/2011
Mon 17/01/2011

如果你想變得可愛,可以將 if/then/else 替換為

If you want to be cute you can replace the if/then/else with

c.add(Calendar.DATE, dayOfWeek > 5 ? (9 - dayOfWeek) : 1);

但我真的想要一些易于理解和可讀的東西.

but I really wanted something easily understood and readable.

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

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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)前星期幾的值)
主站蜘蛛池模板: 欧美日韩国产一区二区三区 | 日日操日日舔 | 91精品国产欧美一区二区 | 美日韩免费视频 | 国产91一区| 久操国产 | 一区二区三区在线观看免费视频 | 91精品国产乱码久久蜜臀 | 免费黄色片在线观看 | 91成人精品视频 | 精品欧美乱码久久久久久1区2区 | 九九久久在线看 | www.久久久.com | 九九亚洲 | 久久综合久久久 | 日本精品999 | 亚洲精品视频一区二区三区 | 成人亚洲视频 | 欧美一级久久精品 | 久久只有精品 | 欧美激情精品久久久久 | 99精品免费久久久久久久久日本 | 精品视频一区二区三区 | 男人午夜视频 | 国产一区二区三区久久久久久久久 | 免费天天干| 国产在线高清 | 性欧美精品一区二区三区在线播放 | 成人亚洲性情网站www在线观看 | 高清视频一区二区三区 | 色天堂影院| 成人在线精品视频 | 韩日一区二区 | 亚洲欧美在线一区 | 99re6在线 | 中文视频在线 | 天天插天天操 | www.久久久久久久久久久久 | 美女黄网 | 久草视频在线看 | 欧美久久一级 |