我正在嘗試將一天的開始時間設定為特定時間。目前,在momentjs中,我可以像這樣開始一天的開始
let now = moment()
console.log('now', now.toString())
console.log('start Day', now.startOf('day').toString()) // Thu Oct 07 2021 00:00:00 GMT 0530
console.log('end day', now.endOf('day').toString()) //Thu Oct 07 2021 23:59:59 GMT 0530
有什么辦法可以讓我從特定時間開始我的一天,就像我想從
2021 年 10 月 7 日星期四 08:00:00 GMT 0530
并結束
2021 年 10 月 7 日星期四 07:59:59 GMT 0530
uj5u.com熱心網友回復:
您可能應該撰寫自己的函式來實作這一點。
function customStartOf(momentObj) {
return momentObj.clone().startOf('day').hours(8);
}
function customEndOf(momentObj) {
// I assume that end of the day is bigger than start of the day
return momentObj.clone().endOf('day').add(1, 'days').hours(7);
}
let now = moment();
console.log('now', now.toString()) ;
console.log('start Day', now.startOf('day').toString());
console.log('end day', now.endOf('day').toString());
console.log('custom start Day', customStartOf(now).toString());
console.log('custom end day', customEndOf(now).toString());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/313689.html
標籤:javascript 约会时间 瞬间
上一篇:有沒有辦法在Python中推斷日期是否是DST(夏令時)更改的實際日期?
下一篇:R中按日期計算的總小時數
