當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDate.getDayOfYear方法代碼示例

本文整理匯總了Java中java.time.LocalDate.getDayOfYear方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.getDayOfYear方法的具體用法?Java LocalDate.getDayOfYear怎麽用?Java LocalDate.getDayOfYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDate的用法示例。


在下文中一共展示了LocalDate.getDayOfYear方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getWeek

import java.time.LocalDate; //導入方法依賴的package包/類
private static int getWeek(LocalDate date) {
    int dow0 = date.getDayOfWeek().ordinal();
    int doy0 = date.getDayOfYear() - 1;
    int doyThu0 = doy0 + (3 - dow0);  // adjust to mid-week Thursday (which is 3 indexed from zero)
    int alignedWeek = doyThu0 / 7;
    int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
    int firstMonDoy0 = firstThuDoy0 - 3;
    if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
    }
    if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
    }
    int week = ((doy0 - firstMonDoy0) / 7) + 1;
    if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
            week = 1;
        }
    }
    return week;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:IsoFields.java

示例2: getWeek

import java.time.LocalDate; //導入方法依賴的package包/類
private static int getWeek(LocalDate date) {

      int dow0 = date.getDayOfWeek().ordinal();
      int doy0 = date.getDayOfYear() - 1;
      int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero)
      int alignedWeek = doyThu0 / 7;
      int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
      int firstMonDoy0 = firstThuDoy0 - 3;
      if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
      }
      if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
      }
      int week = ((doy0 - firstMonDoy0) / 7) + 1;
      if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
          week = 1;
        }
      }
      return week;
    }
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:23,代碼來源:ISOWeeks.java

示例3: test_next

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_next() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);

            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow, date + " " + test);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff > 0 && dayDiff < 8);
                } else {
                    assertSame(month, Month.DECEMBER);
                    assertTrue(date.getDayOfMonth() > 24);
                    assertEquals(test.getYear(), 2008);
                    assertSame(test.getMonth(), Month.JANUARY);
                    assertTrue(test.getDayOfMonth() < 8);
                }
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:TCKTemporalAdjusters.java

示例4: test_previous

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_previous() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);

            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.previous(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow, date + " " + test);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test);
                } else {
                    assertSame(month, Month.JANUARY);
                    assertTrue(date.getDayOfMonth() < 8);
                    assertEquals(test.getYear(), 2006);
                    assertSame(test.getMonth(), Month.DECEMBER);
                    assertTrue(test.getDayOfMonth() > 24);
                }
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:TCKTemporalAdjusters.java

示例5: test_nextOrCurrent

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_nextOrCurrent() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);

            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.nextOrSame(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff < 8);
                    assertEquals(date.equals(test), date.getDayOfWeek() == dow);
                } else {
                    assertFalse(date.getDayOfWeek() == dow);
                    assertSame(month, Month.DECEMBER);
                    assertTrue(date.getDayOfMonth() > 24);
                    assertEquals(test.getYear(), 2008);
                    assertSame(test.getMonth(), Month.JANUARY);
                    assertTrue(test.getDayOfMonth() < 8);
                }
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:28,代碼來源:TCKTemporalAdjusters.java

示例6: test_previousOrCurrent

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_previousOrCurrent() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);

            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.previousOrSame(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff <= 0 && dayDiff > -7);
                    assertEquals(date.equals(test), date.getDayOfWeek() == dow);
                } else {
                    assertFalse(date.getDayOfWeek() == dow);
                    assertSame(month, Month.JANUARY);
                    assertTrue(date.getDayOfMonth() < 7);
                    assertEquals(test.getYear(), 2006);
                    assertSame(test.getMonth(), Month.DECEMBER);
                    assertTrue(test.getDayOfMonth() > 25);
                }
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:28,代碼來源:TCKTemporalAdjusters.java


注:本文中的java.time.LocalDate.getDayOfYear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。