亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于時間調整器的用法。最后一個月()

關于時間調整器的用法。最后一個月()

嗶嗶one 2022-09-14 17:44:41
這是我的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,為什么問題只發生在“十二月”本地日期對象,而不發生在十一月?
查看完整描述

1 回答

?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

請參閱維基百科關于工作日。

示例

星期一 29 十二月 2008 寫 “2009-W01-1”
星期日 3 一月 2010 寫 “2009-W53-7”


你寫了

DateTimeFormatter.ofPattern("YYYY-MM-dd"))

使用模式 ,您正在使用基于周的年份進行格式化。
將模式更改為 ,它使用年份YYYYyyyy-MM-dd

DateTimeFormatter.ofPattern("yyyy-MM-dd"))


查看完整回答
反對 回復 2022-09-14
  • 1 回答
  • 0 關注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號