当前位置: 首页>>代码示例>>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;未经允许,请勿转载。