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


Java LocalDate.from方法代碼示例

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


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

示例1: adjustInto

import java.time.LocalDate; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
    if (isSupportedBy(temporal) == false) {
        throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
    }
    int newWby = range().checkValidIntValue(newValue, WEEK_BASED_YEAR);  // strict check
    LocalDate date = LocalDate.from(temporal);
    int dow = date.get(DAY_OF_WEEK);
    int week = getWeek(date);
    if (week == 53 && getWeekRange(newWby) == 52) {
        week = 52;
    }
    LocalDate resolved = LocalDate.of(newWby, 1, 4);  // 4th is guaranteed to be in week one
    int days = (dow - resolved.get(DAY_OF_WEEK)) + ((week - 1) * 7);
    resolved = resolved.plusDays(days);
    return (R) temporal.with(resolved);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:IsoFields.java

示例2: date

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public MinguoDate date(TemporalAccessor temporal) {
    if (temporal instanceof MinguoDate) {
        return (MinguoDate) temporal;
    }
    return new MinguoDate(LocalDate.from(temporal));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:MinguoChronology.java

示例3: date

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public JapaneseDate date(TemporalAccessor temporal) {
    if (temporal instanceof JapaneseDate) {
        return (JapaneseDate) temporal;
    }
    return new JapaneseDate(LocalDate.from(temporal));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:JapaneseChronology.java

示例4: doWith

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public <R extends DateTime> R doWith(R dateTime, long newValue) {

  int newVal = range().checkValidIntValue(newValue, WEEK_BASED_YEAR);
  LocalDate date = LocalDate.from(dateTime);
  int week = getWeek(date);
  date = date.withDayOfYear(180).withYear(newVal).with(WEEK_OF_WEEK_BASED_YEAR, week);
  return (R) date.with(date);
}
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:10,代碼來源:ISOWeeks.java

示例5: date

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public ThaiBuddhistDate date(TemporalAccessor temporal) {
    if (temporal instanceof ThaiBuddhistDate) {
        return (ThaiBuddhistDate) temporal;
    }
    return new ThaiBuddhistDate(LocalDate.from(temporal));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:ThaiBuddhistChronology.java

示例6: test_TestServiceLoader

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
 public void test_TestServiceLoader() {
    Chronology chrono = Chronology.of("Coptic");
    ChronoLocalDate copticDate = chrono.date(1729, 4, 27);
    LocalDate ld = LocalDate.from(copticDate);
    assertEquals(ld, LocalDate.of(2013, 1, 5), "CopticDate does not match LocalDate");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TCKTestServiceLoader.java

示例7: deserialize

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public LocalDate deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
  return LocalDate.from(formatter.parse(jsonElement.toString()));
}
 
開發者ID:trydent-io,項目名稱:jooby-samples,代碼行數:5,代碼來源:LocalDateAsJson.java

示例8: test_from_TemporalAccessor_invalid_noDerive

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void test_from_TemporalAccessor_invalid_noDerive() {
    LocalDate.from(LocalTime.of(12, 30));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKLocalDate.java

示例9: updateView

import java.time.LocalDate; //導入方法依賴的package包/類
private void updateView() {
    lastSelectedDate = null;

    YearMonthView view = getSkinnable();
    YearMonth yearMonth = view.getYearMonth();

    displayedYearMonth = yearMonth;

    boolean currentYearMonth = getSkinnable().getYearMonth().equals(YearMonth.from(getSkinnable().getToday()));

    monthLabel.getStyleClass().remove(CURRENT_DATE_LABEL);
    yearLabel.getStyleClass().remove(CURRENT_DATE_LABEL);

    if (currentYearMonth && view.isShowToday()) {
        monthLabel.getStyleClass().add(CURRENT_DATE_LABEL);
        yearLabel.getStyleClass().add(CURRENT_DATE_LABEL);
    }

    monthLabel.setText(DateTimeFormatter.ofPattern(Messages.getString("YearMonthViewSkin.MONTH_FORMAT")).format(yearMonth)); //$NON-NLS-1$
    yearLabel.setText(DateTimeFormatter.ofPattern(Messages.getString("YearMonthViewSkin.YEAR_FORMAT")).format(yearMonth)); //$NON-NLS-1$

    // update the week days (mon, tues, wed, ....)

    DayOfWeek dayOfWeek = view.getFirstDayOfWeek();
    for (int i = 0; i < 7; i++) {
        if (view.isShowToday()) {
            if (currentYearMonth) {
                dayOfWeekLabels[i].getStyleClass().add(CURRENT_DATE_BORDER);
            }
            if (currentYearMonth && view.getToday().getDayOfWeek().equals(dayOfWeek)) {
                dayOfWeekLabels[i].getStyleClass().add(CURRENT_DATE_LABEL);
            }
        }
    }


    // update the days (1 .. 31) plus padding days

    final DayOfWeek firstDayOfWeek = getSkinnable().getFirstDayOfWeek();
    LocalDate date = Util.adjustToFirstDayOfWeek(getLoadStartDate(), firstDayOfWeek);

    if (getSkinnable().isShowWeekNumbers()) {
        for (int i = 0; i < 6; i++) {
            int weekOfYear = date.get(getSkinnable().getWeekFields().weekOfYear());
            weekNumberLabels[i].setText(Integer.toString(weekOfYear));
            date = date.plusWeeks(1);
        }
    }

    date = Util.adjustToFirstDayOfWeek(getLoadStartDate(), firstDayOfWeek);

    for (int row = 0; row < 6; row++) {
        for (int col = 0; col < 7; col++) {
            LocalDate localDate = LocalDate.from(date);

            YearMonthView.DateCell cell = cellsMap.get(getKey(row, col));
            cell.setDate(localDate);
            cell.getStyleClass().removeAll(TODAY, DAY_OF_MONTH_LABEL, DAY_NOT_OF_MONTH_LABEL, WEEKEND_DAY, SELECTED_MONTH_DATE);

            if (getSkinnable().getSelectedDates().contains(date)) {
                cell.getStyleClass().add(SELECTED_MONTH_DATE); //$NON-NLS-1$
            }

            if (YearMonth.from(date).equals(YearMonth.from(getSkinnable().getDate()))) {
                if (getSkinnable().isShowToday() && date.equals(getSkinnable().getToday())) {
                    cell.getStyleClass().add(TODAY);
                } else {
                    cell.getStyleClass().add(DAY_OF_MONTH_LABEL); //$NON-NLS-1$
                }
            } else {
                cell.getStyleClass().add(DAY_NOT_OF_MONTH_LABEL); //$NON-NLS-1$
            }

            if (view.getWeekendDays().contains(date.getDayOfWeek())) {
                cell.getStyleClass().add(WEEKEND_DAY); //$NON-NLS-1$
            }

            date = date.plusDays(1);
        }
    }
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:82,代碼來源:YearMonthViewSkin.java

示例10: test_from_TemporalAccessor_null

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void test_from_TemporalAccessor_null() {
    LocalDate.from((TemporalAccessor) null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:TCKLocalDate.java

示例11: date

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Obtains an ISO local date from another date-time object.
 * <p>
 * This is equivalent to {@link LocalDate#from(DateTimeAccessor)}.
 * 
 * @param dateTime the date-time object to convert, not null
 * @return the ISO local date, not null
 * @throws DateTimeException if unable to create the date
 */
@Override
// override with covariant return type
public LocalDate date(DateTimeAccessor dateTime) {

  return LocalDate.from(dateTime);
}
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:16,代碼來源:ISOChrono.java

示例12: ofDateAdjuster

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Obtains a {@code TemporalAdjuster} that wraps a date adjuster.
 * <p>
 * The {@code TemporalAdjuster} is based on the low level {@code Temporal} interface.
 * This method allows an adjustment from {@code LocalDate} to {@code LocalDate}
 * to be wrapped to match the temporal-based interface.
 * This is provided for convenience to make user-written adjusters simpler.
 * <p>
 * In general, user-written adjusters should be static constants:
 * <pre>{@code
 *  static TemporalAdjuster TWO_DAYS_LATER =
 *       TemporalAdjusters.ofDateAdjuster(date -> date.plusDays(2));
 * }</pre>
 *
 * @param dateBasedAdjuster  the date-based adjuster, not null
 * @return the temporal adjuster wrapping on the date adjuster, not null
 */
public static TemporalAdjuster ofDateAdjuster(UnaryOperator<LocalDate> dateBasedAdjuster) {
    Objects.requireNonNull(dateBasedAdjuster, "dateBasedAdjuster");
    return (temporal) -> {
        LocalDate input = LocalDate.from(temporal);
        LocalDate output = dateBasedAdjuster.apply(input);
        return temporal.with(output);
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:TemporalAdjusters.java

示例13: Transaction

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Construct a Transaction instance with the given amount at the given day.
 * @param amount the amount transferred
 * @param when the day the transaction took place
 */
public Transaction(double amount, Date when) {
    this.amount = amount;
    this.when = LocalDate.from(when.toInstant().atZone(ZoneId.systemDefault()));
}
 
開發者ID:RayDeCampo,項目名稱:java-xirr,代碼行數:10,代碼來源:Transaction.java

示例14: date

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Obtains an ISO local date from another date-time object.
 * <p>
 * This is equivalent to {@link LocalDate#from(TemporalAccessor)}.
 *
 * @param temporal  the date-time object to convert, not null
 * @return the ISO local date, not null
 * @throws DateTimeException if unable to create the date
 */
@Override  // override with covariant return type
public LocalDate date(TemporalAccessor temporal) {
    return LocalDate.from(temporal);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:IsoChronology.java

示例15: clone

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Returns a task with the same name, start date and end date as this one. <br>
 * Important: the children list is NOT copied. 
 * 
 */
@Override
public GanttTask clone() {
	return new GanttTask(name, LocalDate.from(startDate), LocalDate.from(endDate));
}
 
開發者ID:vibridi,項目名稱:qgu,代碼行數:10,代碼來源:GanttTask.java


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