這是我的jsp頁面源代碼:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ page import="java.time.format.DateTimeFormatter"%> <%@ page import="java.time.temporal.TemporalAdjusters"%> <%@ page import="java.time.LocalDate"%> <!DOCTYPE html><html><head><meta charset="UTF-8"><title>Local Date Demo</title></head><body><%int year=2018,month=12,date=1;LocalDate theMonthShiftStartDate=LocalDate.of(year,month,date);LocalDate theMonthShiftEndDate=theMonthShiftStartDate.with(TemporalAdjusters.lastDayOfMonth()); LocalDate previousMonthShiftStartDate=theMonthShiftStartDate.plusMonths(-1);LocalDate previousMonthShiftEndDate=previousMonthShiftStartDate.with(TemporalAdjusters.lastDayOfMonth());%>theMonthShiftStartDate=<%=theMonthShiftStartDate.format(DateTimeFormatter.ofPattern("YYYY-MM-dd"))%><br>theMonthShiftEndDate=<%=theMonthShiftEndDate.format(DateTimeFormatter.ofPattern("YYYY-MM-dd"))%><br>previousMonthShiftStartDate=<%=previousMonthShiftStartDate.format(DateTimeFormatter.ofPattern("YYYY-MM-dd"))%><br>previousMonthShiftEndDate=<%=previousMonthShiftEndDate.format(DateTimeFormatter.ofPattern("YYYY-MM-dd"))%><br></body></html>為什么輸出如下: theMonthShiftStartDate=2018-12-01 theMonthShiftEndDate=2019-12-31 previousMonthShiftStartDate=2018-11-01 previousMonthShiftEndDate=2018-11-30我預(yù)計(jì)“月移日期”應(yīng)該是2018-12-31,但是,它返回2019-12-31。根據(jù)爪哇多克: TemporalAdjusters.lastDayOfMonth() 返回“每月的最后一天”調(diào)整器,該調(diào)整器返回設(shè)置為當(dāng)前月份的最后一天的新日期。我今天運(yùn)行jsp,為什么問題只發(fā)生在“十二月”本地日期對象,而不發(fā)生在十一月?
添加回答
舉報(bào)
0/150
提交
取消