我需要使用以下格式的下一个15日期: 15.06.2015 23:59:59
例子:
15.06.2015 23:59:59.15.08.2015 23:59:5915.03.2015 23:59:59我需要几秒钟的结果.
我知道如何在PHP中执行此操作,但未能使其与JavaScript一起使用.
非常感谢您的帮助!
你可以尝试类似的东西
var date = new Date();
//if 15th of current month is over move to next month
//need to check whether to use >= or just > ie on 15th Jun
//if you want 15 Jun then use > else if you want 15 Jul use >=
var dt = date.getDate();
date.setDate(15);
if (dt >= 15) {
date.setMonth(date.getMonth() + 1);
}
date.setHours(23, 59, 59, 0);
document.write(date)Run Code Online (Sandbox Code Playgroud)
如果需要一个返回新日期对象的函数
function setNext15(date) {
var next = new Date(date);
var cache = next.getDate();
next.setDate(15);
if (cache >= 15) {
next.setMonth(date.getMonth() + 1);
}
next.setHours(23, 59, 59, 0);
console.log(next, date);
return next;
}
Run Code Online (Sandbox Code Playgroud)
演示:小提琴