本文整理汇总了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;
}
示例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());
}
示例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;
}
示例4: convert
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public LocalDate convert(ZonedDateTime source) {
return source.toLocalDate();
}