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


Java ZonedDateTime.toLocalDate方法代碼示例

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


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

示例1: isRecurrenceShowing

import java.time.ZonedDateTime; //導入方法依賴的package包/類
private boolean isRecurrenceShowing(Entry<?> entry, ZonedDateTime st, ZonedDateTime et, ZoneId zoneId) {
    String recurrenceRule = entry.getRecurrenceRule();

    LocalDate utilStartDate = entry.getStartAsZonedDateTime().toLocalDate();

    try {
        LocalDate utilEndDate = et.toLocalDate();

        LocalDateIterator iterator = LocalDateIteratorFactory.createLocalDateIterator(recurrenceRule, utilStartDate, zoneId, true);

        /*
         * TODO: for performance reasons we should definitely
         * use the advanceTo() call, but unfortunately this
         * collides with the fact that e.g. the DetailedWeekView loads
         * data day by day. So a given day would not show
         * entries that start on the day before but intersect
         * with the given day. We have to find a solution for
         * this.
         */
        // iterator.advanceTo(org.joda.time.LocalDate.fromDateFields(Date.from(st.toInstant())));

        while (iterator.hasNext()) {
            LocalDate repeatingDate = iterator.next();
            if (repeatingDate.isAfter(utilEndDate)) {
                break;
            } else {
                ZonedDateTime recurrenceStart = ZonedDateTime.of(repeatingDate, LocalTime.MIN, zoneId);
                ZonedDateTime recurrenceEnd = recurrenceStart.plus(entry.getDuration());

                if (Util.intersect(recurrenceStart, recurrenceEnd, st, et)) {
                    return true;
                }
            }
        }
    } catch (ParseException ex) {
        ex.printStackTrace();
    }

    return false;
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:41,代碼來源:Entry.java

示例2: calculateSourceBoundsFromRecurrenceBounds

import java.time.ZonedDateTime; //導入方法依賴的package包/類
private Interval calculateSourceBoundsFromRecurrenceBounds(Entry<?> source, Entry<?> recurrence, Interval oldInterval) {
    ZonedDateTime recurrenceStart = recurrence.getStartAsZonedDateTime();
    ZonedDateTime recurrenceEnd = recurrence.getEndAsZonedDateTime();

    Duration startDelta = Duration.between(oldInterval.getStartZonedDateTime(), recurrenceStart);
    Duration endDelta = Duration.between(oldInterval.getEndZonedDateTime(), recurrenceEnd);

    ZonedDateTime sourceStart = source.getStartAsZonedDateTime();
    ZonedDateTime sourceEnd = source.getEndAsZonedDateTime();

    sourceStart = sourceStart.plus(startDelta);
    sourceEnd = sourceEnd.plus(endDelta);

    return new Interval(sourceStart.toLocalDate(), sourceStart.toLocalTime(), sourceEnd.toLocalDate(), sourceEnd.toLocalTime(), source.getZoneId());
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:16,代碼來源:Calendar.java

示例3: calcCancellationFee

import java.time.ZonedDateTime; //導入方法依賴的package包/類
/**
 * Calculates and returns the cancellation fee that should be assessed when a user cancels a
 * booking.
 *
 * This method uses the new Java 8 Time API, which a little confusing at first, but way more
 * useful (and easier to use) than the nightmarish way things used to be done.
 *
 * It does NOT account for time zones, since in the real world, this code would be running
 * server side, not client side, and then time zones would not matter.
 *
 * Sadly, the new Java Time and Date API is almost laughably annoying in that there is NO built
 * in easy way to transform an existing Java Date object into a new time api date object,
 * excepting the toInstant method, which brings with it it's own cluttered bag of complications.
 * Why?!?
 *
 * @param booking The booking to calculate cancellation fees for.
 *
 * @return The cancellation fee to cancel the provided booking.
 */
public static double calcCancellationFee(Booking booking) {
    // Define some useful dates for our calculations
    LocalDate today = LocalDate.now();
    Date temp = booking.getCheckInDate();
    ZonedDateTime zdt = Instant.ofEpochMilli(temp.getTime()).atZone(ZoneId.systemDefault());
    LocalDate checkInDate = zdt.toLocalDate();
    temp = booking.getCreatedDate();
    zdt = Instant.ofEpochMilli(temp.getTime()).atZone(ZoneId.systemDefault());
    LocalDate bookingCreationDate = LocalDate.from(zdt);
    long daysTillCheckIn = today.until(checkInDate, ChronoUnit.DAYS);

    // Determine the fee percentage based on specifications
    double feePercentage;
    if(bookingCreationDate.plusDays(2).isAfter(today)) {
        feePercentage = 0.00;
    } else if(daysTillCheckIn > 30) {
        feePercentage = 20.00;
    } else if(daysTillCheckIn > 7) {
        feePercentage = 30.00;
    } else {
        feePercentage = 60.00;
    }

    // Calculate the fee from the bill and the fee percentage
    double fee = 0.00;

    for(BillItem item : booking.getBill().getCharges()) {
        double totalItemPrice = item.getTotalPrice();
        // Check for cases where another discount is applied, etc.
        if(item.getTotalPrice() > 0) {
            fee += (totalItemPrice * feePercentage);
        }
    }

    return fee;
}
 
開發者ID:maillouxc,項目名稱:git-rekt,代碼行數:56,代碼來源:BookingService.java

示例4: convert

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@Override
public LocalDate convert(ZonedDateTime source) {
	return source.toLocalDate();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:5,代碼來源:DateTimeConverters.java


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