本文整理匯總了Java中java.time.LocalDate.with方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.with方法的具體用法?Java LocalDate.with怎麽用?Java LocalDate.with使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.with方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getProfNotifications
import java.time.LocalDate; //導入方法依賴的package包/類
@GetMapping(value = "/prof/noti")
public String getProfNotifications(Model model) {
try {
LocalDate currDate = LocalDate.now();
if (currDate.getDayOfWeek().equals(DayOfWeek.SATURDAY)
|| currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY))
currDate = currDate.plus(3, ChronoUnit.DAYS);
LocalDate startDateOfSchoolWeek = currDate.with(DayOfWeek.MONDAY);
String profEmail = authFacade.getAuthentication().getName();
Professor prof = professorService.getProfessorByEmail(profEmail);
List<BookingSlot> profBookings
= bookingSlotService.getSlotsByProfAndSWeek(prof.getAlias(), startDateOfSchoolWeek);
model.addAttribute("bookings", filterBookingSlots(profBookings));
return "fragments/prof_noti";
} catch (Exception ex) {
ex.printStackTrace();
model.addAttribute("message", ex.toString());
return "error";
}
}
示例2: test_withDayOfWeek
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_withDayOfWeek(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2012, 12, 15); // Safely in the middle of a month
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField womField = week.weekOfMonth();
TemporalField woyField = week.weekOfYear();
int wom = day.get(womField);
int woy = day.get(woyField);
for (int dow = 1; dow <= 7; dow++) {
LocalDate result = day.with(dowField, dow);
assertEquals(result.get(dowField), dow, String.format("Incorrect new Day of week: %s", result));
assertEquals(result.get(womField), wom, "Week of Month should not change");
assertEquals(result.get(woyField), woy, "Week of Year should not change");
}
}
示例3: getStudentNotifications
import java.time.LocalDate; //導入方法依賴的package包/類
@GetMapping(value = "/student/noti")
public String getStudentNotifications(Model model) {
try {
LocalDate currDate = LocalDate.now();
if (currDate.getDayOfWeek().equals(DayOfWeek.SATURDAY)
|| currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY))
currDate = currDate.plus(3, ChronoUnit.DAYS);
LocalDate startDateOfSchoolWeek = currDate.with(DayOfWeek.MONDAY);
String studentEmail = authFacade.getAuthentication().getName();
Student student = studentService.getStudentByEmail(studentEmail);
List<BookingSlot> studentBookings
= bookingSlotService.getSlotsByStudentAndSWeek(student.getId(), startDateOfSchoolWeek);
model.addAttribute("bookings", filterStudentBookings(studentBookings));
return "fragments/student_noti";
} catch (Exception ex) {
ex.printStackTrace();
model.addAttribute("message", ex.toString());
return "error";
}
}
示例4: getTimesheetWeekStartDate
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* Returns java.util weekend date (Sunday) for a given date.
*
* @return
*/
public static Date getTimesheetWeekStartDate(Date inputDate) {
log.info("Inside getTimesheetWeekStartDate :: inputDate: " + inputDate);
if (inputDate != null) {
LocalDate localDate = inputDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate firstMonday = localDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
log.info("Inside inputdate not null loop, firstMonday: " + firstMonday);
return Date.from(firstMonday.atStartOfDay(ZoneId.systemDefault()).toInstant());
} else {
log.error("Input date not found. So returning null.");
return null;
}
}
示例5: previous
import java.time.LocalDate; //導入方法依賴的package包/類
private LocalDate previous(LocalDate date) {
int newDayOfMonth = date.getDayOfMonth() - 1;
if (newDayOfMonth > 0) {
return date.withDayOfMonth(newDayOfMonth);
}
date = date.with(date.getMonth().minus(1));
if (date.getMonth() == Month.DECEMBER) {
date = date.withYear(date.getYear() - 1);
}
return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear())));
}
示例6: getTimesheetWeekEndDate
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* Returns java.util weekend date (Sunday) for a given date.
*
* @return
*/
public static Date getTimesheetWeekEndDate(Date inputDate) {
log.info("Inside getTimesheetWeekEndDate :: inputDate: " + inputDate);
if (inputDate != null) {
LocalDate localDate = inputDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate lastSunday = localDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
log.info("Inside input date not null loop, lastSunday: " + lastSunday);
return Date.from(lastSunday.atStartOfDay(ZoneId.systemDefault()).toInstant());
} else {
log.error("Input date not found. So returning null.");
return null;
}
}
示例7: test_withWeekOfWeekBasedYear
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2012, 12, 31);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField wowbyField = week.weekOfWeekBasedYear();
TemporalField yowbyField = week.weekBasedYear();
int dowExpected = (day.get(dowField) - 1) % 7 + 1;
LocalDate dowDate = day.with(dowField, dowExpected);
int dowResult = dowDate.get(dowField);
assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);
int weekExpected = day.get(wowbyField) + 1;
ValueRange range = day.range(wowbyField);
weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
LocalDate weekDate = day.with(wowbyField, weekExpected);
int weekResult = weekDate.get(wowbyField);
assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);
int yearExpected = day.get(yowbyField) + 1;
LocalDate yearDate = day.with(yowbyField, yearExpected);
int yearResult = yearDate.get(yowbyField);
assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day + " --> " + yearDate);
range = yearDate.range(wowbyField);
weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());
int weekActual = yearDate.get(wowbyField);
assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}
示例8: main
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* 程序執行入口.
*
* @param args 命令行參數
*/
public static void main(String[] args) {
LocalDate today = LocalDate.now();
//Get the Year, check if it's leap year
System.out.println("Year " + today.getYear() + " is Leap Year? " + today.isLeapYear());
//Compare two LocalDate for before and after
System.out.println("Today is before 01/01/2015? " + today.isBefore(LocalDate.of(2015, 1, 1)));
//Create LocalDateTime from LocalDate
System.out.println("Current Time=" + today.atTime(LocalTime.now()));
//plus and minus operations
System.out.println("10 days after today will be " + today.plusDays(10));
System.out.println("3 weeks after today will be " + today.plusWeeks(3));
System.out.println("20 months after today will be " + today.plusMonths(20));
System.out.println("10 days before today will be " + today.minusDays(10));
System.out.println("3 weeks before today will be " + today.minusWeeks(3));
System.out.println("20 months before today will be " + today.minusMonths(20));
//Temporal adjusters for adjusting the dates
System.out.println("First date of this month= " + today.with(TemporalAdjusters.firstDayOfMonth()));
LocalDate lastDayOfYear = today.with(TemporalAdjusters.lastDayOfYear());
System.out.println("Last date of this year= " + lastDayOfYear);
Period period = today.until(lastDayOfYear);
System.out.println("Period Format= " + period);
System.out.println("Months remaining in the year= " + period.getMonths());
}
示例9: test_adjust1
import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_adjust1() {
LocalDate base = IsoChronology.INSTANCE.date(1728, 10, 28);
LocalDate test = base.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(test, IsoChronology.INSTANCE.date(1728, 10, 31));
}
示例10: getMonthStart
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* 得到當月起始時間
*
* @param date 日期
* @return 傳入的日期當月的開始日期
*/
public static LocalDate getMonthStart(LocalDate date) {
return date.with(TemporalAdjusters.firstDayOfMonth());
}
示例11: getYearStart
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* 得到當前年起始時間
*
* @param date 日期
* @return 傳入的日期當年的開始日期
*/
public static LocalDate getYearStart(LocalDate date) {
return date.with(TemporalAdjusters.firstDayOfYear());
}
示例12: getYearEnd
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* 得到當前年最後一天
*
* @param date 日期
* @return 傳入的日期當年的結束日期
*/
public static LocalDate getYearEnd(LocalDate date) {
return date.with(TemporalAdjusters.lastDayOfYear());
}
示例13: getWeekStart
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* 得到傳入日期,周起始時間
* 這個方法定義:周一為一個星期開始的第一天
*
* @param date 日期
* @return 返回一周的第一天
*/
public static LocalDate getWeekStart(LocalDate date) {
return date.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
}
示例14: getWeekEnd
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* 得到當前周截止時間
* 這個方法定義:周日為一個星期開始的最後一天
*
* @param date 日期
* @return 返回一周的最後一天
*/
public static LocalDate getWeekEnd(LocalDate date) {
return date.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY));
}
示例15: getMonthEnd
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* 得到month的終止時間點.
*
* @param date 日期
* @return 傳入的日期當月的結束日期
*/
public static LocalDate getMonthEnd(LocalDate date) {
return date.with(TemporalAdjusters.lastDayOfMonth());
}