如何在javascript日期对象中获取下一个12:00:00PM

ric*_*uck 3 javascript date

只需要知道如何在 JavaScript 日期对象中获得最接近的 12:00:00pm,出于某种原因,我很困惑!例如,如果是 7 月 1 日上午 09:00,那么它将是 7 月 1 日下午 12:00,但是如果是 7 月 1 日下午 01:00,那么我需要在 7 月 2 日下午 12:00 返回。

干杯。

mpl*_*jan 6

像这样:如果小时数 > 12,则添加一天

var nextNoon = new Date();
if (nextNoon.getHours() >= 12) nextNoon.setDate(nextNoon.getDate() + 1)
nextNoon.setHours(12, 0, 0, 0)
console.log(nextNoon)
Run Code Online (Sandbox Code Playgroud)