本文整理汇总了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());
}