我想把時間安排在 23:59:59。現在它正在列印 05 2022 00:00:00,我的要求是 Sat Nov 05 2022 23:59:59。
var now = new Date();
var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var lastSunday = new Date(today.setDate(today.getDate()-today.getDay()));
var from = new Date(lastSunday.getTime() - (7*24*60*60*1000));
var to = new Date(lastSunday.getTime() - (1*24*60*60*1000));
輸出:
console.log(now.toString()) //today Thu Nov 10 2022 13:20:22 GMT 0530 (India Standard Time)
console.log(from.toString()) // Sun Oct 30 2022 00:00:00 GMT 0530 (India Standard Time)
console.log(to.toString()) //Sat Nov 05 2022 00:00:00 GMT 0530 (India Standard Time)
uj5u.com熱心網友回復:
希望對你有幫助!!
const myFunction = () => {
var now = new Date();
var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var lastSunday = new Date(today.setDate(today.getDate() - today.getDay()));
var temp = new Date(lastSunday.getTime() - 1000);
document.getElementById("temp").innerHTML = temp;
};
<body onload="myFunction()">
<h1 id="temp"></h1>
</body>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/531162.html
標籤:javascript反应反应式约会时间ecmascript-6
上一篇:反應原生分頁重復問題
