这是我的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
我预计“月移日期”应该是2018-12-31,但是,它返回2019-12-31。
根据爪哇多克:
TemporalAdjusters.lastDayOfMonth()
返回“每月的最后一天”调整器,该调整器返回设置为当前月份的最后一天的新日期。
我今天运行jsp,为什么问题只发生在“十二月”本地日期对象,而不发生在十一月?
慕容708150
相关分类