我正在使用 Moment.js 在我正在處理的網站上顯示時間和日期。我有一個顯示今天的天氣模塊,但我還想顯示未來 3 天的預報。我可以使用 Moment.js 獲取 Tomorrow、Tomorrow + 1 和 Tomorrow + 2,但我不知道如何更改它們的格式,使其顯示為“WED、THU、FRI”。這是我目前擁有的:var today = moment().format('MMMM D, YYYY');var d1 = moment().add(1, 'days').calendar().format('ddd');var d2 = moment().add(2, 'days').calendar().format('ddd');var d3 = moment().add(3, 'days').calendar().format('ddd');我得到的錯誤是這moment(...).add(...).calendar(...).format不是一個功能。如果我使用這個代碼:var d1 = moment().add(1, 'days');然后console.log()那個變量,我可以看到:所以 M {_isAMomentObject: true, _isUTC: false, _pf: {…}, _locale: P, _d: Thu Nov 28 2019 08:51:46 GMT-0600 (Central Standard Time), …}我知道它是可用的,我只是不知道顯示星期幾的三個字符標簽的正確語法。
Moment.js - 獲取明天并顯示它的星期幾
米脂
2022-01-13 15:45:59