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

java日歷setFirstDayOfWeek不起作用

java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
本文介紹了java日歷setFirstDayOfWeek不起作用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

現在是真正的日歷:

   March 2015       
Su Mo Tu We Th Fr Sa  
 1  2  3  4  5  6  7  
 8  9 10 11 12 13 14  
15 16 17 18 19 20 21  
22 23 24 25 26 27 28  
29 30 31   

我得到 DAY_OF_WEEK of 2015/3/24 像這樣:

And I get DAY_OF_WEEK of 2015/3/24 like this:

public class TestCalendar {
    public static void main(String[] argvs){
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.set(2015,Calendar.MARCH,24);
        System.out.println(cal.get(Calendar.DAY_OF_WEEK));
    }
}

因為我有 cal.setFirstDayOfWeekMONDAY,所以我期望的結果是 2,但是無論哪一天我都設置為 first星期幾(已嘗試過 SUNDAY 和其他人).它一直向我顯示相同的結果,即 3.所以看來 firstDayOfWeek 不會影響結果.

Since I have cal.setFirstDayOfWeek to MONDAY the result I expecting is 2, but Whatever day I set to the first day of week(have tried SUNDAY and others) .It kept show me the same result which is 3. So It seemed that firstDayOfWeek won't affect the result.

我是不是做錯了什么?

編輯

我剛剛想到并感謝下面的答案,這個 setFirstDayOfWeek 不會影響 get(Calendar.DAY_OF_WEEK) 也不會影響 get(Calendar.WEEK_OF_YEAR)

I just figured and thanks to answers below, that this setFirstDayOfWeek will not affect the result of get(Calendar.DAY_OF_WEEK) nor get(Calendar.WEEK_OF_YEAR)

那么setFirstDayOfWeek()這個方法是為什么呢?我的意思是我如何告訴程序我希望 2015/3/29 成為第 12 周的最后一天,而不是將其視為第 13 周的第一天?

Then what is this method setFirstDayOfWeek() designed for? I mean How can I told the program that I want 2015/3/29 be the last day of the 12th week instead of treating it as the first day of the 13th week?

推薦答案

tl;dr

LocalDate.of( 2015 , Month.MARCH , 24 )  // `LocalDate` object for 2015-03-24.
         .getDayOfWeek()                 // DayOfWeek.TUESDAY constant object
         .getValue()                     // 2

避免使用舊的日期時間類

Calendar 是一團糟,它的兄弟類也是如此.幸運的是,這些舊的日期時間類現在已被 java.time 類所取代.

Avoid legacy date-time classes

Calendar is a ugly mess, as are its sibling classes. Fortunately these old date-time classes are now legacy, supplanted by the java.time classes.

如果您希望星期一作為一周的第一天,星期日是最后一天,編號為 1-7,然后使用 ISO 8601 日歷在 java.time 類中默認使用.

If you want Monday as the first day of the week, Sunday the last, numbered 1-7, then use the ISO 8601 calendar used by default in the java.time classes.

DayOfWeek 枚舉為一周中的每個 ISO 天保存預定義的對象.如果需要,您可以詢問其數量,但通常最好傳遞此枚舉的對象而不是單純的整數.

The DayOfWeek enum hold predefined objects for each of those ISO days of the week. You can interrogate for its number if need be, though generally better to pass around objects of this enum rather than mere integers.

LocalDate 類表示沒有時間和時區的僅日期值.

The LocalDate class represents a date-only value without time-of-day and without time zone.

LocalDate ld = LocalDate.of( 2015 , Month.MARCH , 24 );
DayOfWeek dow = ld.getDayOfWeek();
int value = dow.getValue(); // 1-7 for Monday-Sunday. But often better to use the `DayOfWeek` object rather than a mere integer number.

有關星期一不是第一天的一周的其他定義,請參閱 WeekFields 類.

For working with other definitions of a week where Monday is not day number one, see the WeekFields class.

java.time 框架內置于 Java 8 及更高版本.這些類取代了麻煩的舊 legacy 日期時間類,例如 java.util.Date, 日歷, &SimpleDateFormat.

The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.

Joda-Time 項目,現在在 維護模式,建議遷移到 java.time 類.

The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.

要了解更多信息,請參閱 Oracle 教程.并在 Stack Overflow 上搜索許多示例和解釋.規范是 JSR 310.

To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.

從哪里獲得 java.time 類?

Where to obtain the java.time classes?

  • Java SE 8SE 9 及更高版本
    • 內置.
    • 標準 Java API 的一部分,帶有捆綁實現.
    • Java 9 添加了一些小功能和修復.
    • 大部分 java.time 功能都向后移植到 Java 6 &7 在 ThreeTen-Backport.
    • ThreeTenABP項目適應ThreeTen-Backport(上面提到過)專門用于 Android.
    • 請參閱如何使用 ThreeTenABP….
    • The ThreeTenABP project adapts ThreeTen-Backport (mentioned above) for Android specifically.
    • See How to use ThreeTenABP….

    ThreeTen-Extra 項目通過附加類擴展了 java.time.該項目是未來可能添加到 java.time 的試驗場.您可以在這里找到一些有用的類,例如 間隔YearWeek, YearQuarter 和 更多.

    The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.

    這篇關于java日歷setFirstDayOfWeek不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
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 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
The correct way to set and get hour, minutes, sec(設置和獲取小時、分鐘、秒的正確方法)
主站蜘蛛池模板: 99久久久国产精品免费消防器 | 网色| 久草成人网 | 最新中文字幕一区 | 天天综合亚洲 | 91精品国产乱码久久久久久久 | 国产精品久久久久久婷婷天堂 | 久久久久久久久久久一区二区 | 国产精品夜夜夜一区二区三区尤 | 一区二区三区四区视频 | 99色视频| 精品久久久久久亚洲精品 | 夜夜爽夜夜操 | 特黄色毛片 | 国产精品福利在线 | av喷水 | 国产精品欧美一区二区 | 国产精品久久久久久亚洲调教 | 亚洲第一av网站 | 久久久久久久国产精品视频 | 久久伊人在 | 三级视频国产 | 男女下面一进一出网站 | 欧美一区二区三区视频在线观看 | 精品不卡 | 婷婷桃色网| 欧美日韩在线免费观看 | 欧美激情综合五月色丁香小说 | 中文字幕一区二区三区精彩视频 | 6080亚洲精品一区二区 | 亚洲成人第一页 | 日本黄色的视频 | 国产一级在线 | 伊人免费网 | 欧美精产国品一二三区 | 日本久久精品视频 | 亚洲欧美日韩一区二区 | 97在线超碰 | 网络毛片 | 久久99精品国产99久久6男男 | 午夜小电影 |