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

java日歷setFirstDayOfWeek不起作用

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

問題描述

限時送ChatGPT賬號..

現(xiàn)在是真正的日歷:

   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,所以我期望的結(jié)果是 2,但是無論哪一天我都設(shè)置為 first星期幾(已嘗試過 SUNDAY 和其他人).它一直向我顯示相同的結(jié)果,即 3.所以看來 firstDayOfWeek 不會影響結(jié)果.

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 是一團(tuán)糟,它的兄弟類也是如此.幸運的是,這些舊的日期時間類現(xiàn)在已被 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 類中默認(rèn)使用.

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 天保存預(yù)定義的對象.如果需要,您可以詢問其數(shù)量,但通常最好傳遞此枚舉的對象而不是單純的整數(shù).

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 類表示沒有時間和時區(qū)的僅日期值.

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.

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

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

java.time 框架內(nèi)置于 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 項目,現(xiàn)在在 維護(hù)模式,建議遷移到 java.time 類.

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

要了解更多信息,請參閱 Oracle 教程.并在 Stack Overflow 上搜索許多示例和解釋.規(guī)范是 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 及更高版本
    • 內(nèi)置.
    • 標(biāo)準(zhǔn) Java API 的一部分,帶有捆綁實現(xiàn).
    • Java 9 添加了一些小功能和修復(fù).
    • 大部分 java.time 功能都向后移植到 Java 6 &7 在 ThreeTen-Backport.
    • ThreeTenABP項目適應(yīng)ThreeTen-Backport(上面提到過)專門用于 Android.
    • 請參閱如何使用 ThreeTenABP….
    • The ThreeTenABP project adapts ThreeTen-Backport (mentioned above) for Android specifically.
    • See How to use ThreeTenABP….

    ThreeTen-Extra 項目通過附加類擴(kuò)展了 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.

    這篇關(guān)于java日歷setFirstDayOfWeek不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
The correct way to set and get hour, minutes, sec(設(shè)置和獲取小時、分鐘、秒的正確方法)
主站蜘蛛池模板: 亚洲成av人片在线观看 | av一二三四| 成人午夜毛片 | 丁香婷婷成人 | 一本色道精品久久一区二区三区 | 九九热这里 | 夜夜干夜夜操 | 欧美一级二级三级视频 | 小川阿佐美pgd-606在线 | 国产乱码精品一区二区三区忘忧草 | 精品一区二区三区中文字幕 | 久久视频精品 | 成人国产午夜在线观看 | 精品国产一区二区三区四区在线 | 国产午夜精品一区二区三区四区 | 一级毛毛片| 成人性生交大片免费看中文带字幕 | 黄色一级电影免费观看 | 国产精品成人国产乱一区 | 国产粉嫩尤物极品99综合精品 | 狠狠干网站 | 精品欧美乱码久久久久久1区2区 | 亚洲欧美中文字幕在线观看 | 91亚洲精华国产 | 北条麻妃国产九九九精品小说 | 精品国产一区二区在线 | 亚洲日本欧美 | 午夜在线小视频 | 亚洲精品一| 亚洲一区欧美一区 | 网站国产 | 国产成人精品一区二区三区网站观看 | 国产精品久久久乱弄 | 国产精品亚洲综合 | 91精品国产91久久久久久丝袜 | 91精品久久久久久久久 | 综合色播| 国产精品国产三级国产播12软件 | 国产女人第一次做爰毛片 | 永久精品| 欧美国产视频 |