任何建议?解决方案您可能会遇到时区问题,请记住,在JavaScript中,Date类表示时间戳,是自1970年1月1日以来的毫秒数(00:00)UTC. Mozilla Javascript文档-日期请看一下这篇帖子,进行有趣的讨论((Javascript日期对象是否总是一天休假?)[ JavaScript日期对象是否总是一天休假? 我一直在使用其中一种方法来解决此问题, 导出函数dateFromModel(d:Date):Date {const doo = new Date(d);返回新的Date(doo.getTime()+ Math.abs(doo.getTimezoneOffset()* 60000));} 更新:我认为您现在遇到了我提到的问题,加上您现在正在使用动量切换月份和日期.只需在使用时刻之前和之后打印日期,即可进行检查.您还可以使用 toISOString()来检查后端要接收的内容,此JavaScript函数与Java LocalDate 一样符合ISO 8601.I don't know why, when you enter a date, it give me back the same date but with one day less.service.ts protected convertDateFromClient(project: IProject): IProject { const copy: IProject = Object.assign({}, project, { entryDate: project.entryDate != null ? moment(project.entryDate, 'DD/MM/YYYY').format('YYYY-MM-DD') : null }); return copy; }Project.java...@Column(name = "entry_date") private LocalDate entryDate;public LocalDate getEntryDate() { return entryDate; } public Project entryDate(LocalDate entryDate) { this.entryDate = entryDate; return this; } public void setEntryDate(LocalDate entryDate) { this.entryDate = entryDate; }The date entered: 12/2/2020 and return: 11/2/2020Update: If I put the date 12/02/2020 (dd/MM/yyyy) by keyboard in the datePicker´s input, i recived from POST this 01/12/2020 (MM/dd/yyyy)Any suggestions??? 解决方案 You might be having a problem with time zones, remember that in JavaScript Date class represent a timestamp, is the number of miliseconds since January 1, 1970 00:00 UTC.Mozilla Javascript Doc - DateTake a look at this post for an interesting discussion, (Is the Javascript date object always one day off?)[Is the Javascript date object always one day off?I have been using one of this methods to solve this issue,export function dateFromModel(d: Date): Date { const doo = new Date(d); return new Date(doo.getTime() + Math.abs(doo.getTimezoneOffset() * 60000));}UPDATE:I think you now have the problem I mention, plus you now are switching month and days when using moment. Just print the date before using moment and after, to check this. You can also use toISOString() to check what are you going to receive in the backend, this JavaScript function complies to ISO 8601 just like Java LocalDate. 这篇关于减去Moment和LocalDate之间的转换天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-08 12:57