我需要所有星期六和当年的星期日
我正在使用此功能
var x = new Date();
//set the financial year starting date
var currentyear = x.getFullYear();
var nextyear = x.getFullYear() + 1;
x.setFullYear(currentyear, 00, 00);
//set the next financial year starting date
var y = new Date();
y.setFullYear(currentyear, 12, 31);
var j = 1;
var count = 0;
//getting the all mondays in a financial year
for (var i = 0; x < y; i += j) {
if (x.getDay() === 0) {
//console.log("Date : " + x.getDate() + "/" +
// (x.getMonth() + 1) + "<br>");
x = new Date(x.getTime() + (7 * 24 * 60 * 60 * 1000));
// x = new Date(x.getFullYear(), x.getMonth(), x.getDate());
holidaylist.push(x);
j = 7;
count++;
} else {
j = 1;
x = new Date(x.getTime() + (24 * 60 * 60 * 1000));
}
}
它给了我完美的星期六和星期日,但问题是
我不希望任何时间落后于我的约会
从
Sat Mar 03 1973 15:16:40 GMT+0530 (India Standard Time)
我想要这样的东西
以
Sat Mar 03 1973 00:00:00 GMT+0530 (India Standard Time)
如何从此功能获得00时间
答案 0 :(得分:1)
尝试toDateString();
let z = new Date();
console.log(z);
console.log(new Date(z.toDateString()))
&#13;
答案 1 :(得分:1)
您可以使用javascript的setHours属性来设置日期对象的时间 尝试使用
(new Date()).setHours(0, 0, 0, 0);
function myFunction() {
var d = new Date();
d.setHours(0,0,0,0);
document.getElementById("demo").innerHTML = d;
}
<p>Click the button to display the date after setting the time.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
答案 2 :(得分:1)
你可以尝试
router.post('/cms', (req, res) => {
console.log(req.body);
db.prepare(`INSERT INTO blogposts (title, body) VALUES (${req.body.main_title}, ${req.body.content})`).run();
res.send('post added to database!');
})