如何使用 moment.js 正确获取星期几(名称)?

how to properly get day of the week (name) with moment.js?

我正在使用 https://openweathermap.org/ api。它以秒为单位提供时区。如何使用 moment.js 正确获取星期几(名称)?

 const timezoneInMinutes = 7200 / 60;
 const currentDate = moment().utcOffset(timezoneInMinutes).format("YYYY-MM-DD");
 console.log(currentDate) // 2022-05-13
 console.log(moment().day(currentDate).format("dddd")); // "Sunday" ????

您正在将 currentDate 放入 day(),您需要将其放入 moment()

const timezoneInMinutes = 7200 / 60;
const currentDate = moment().utcOffset(timezoneInMinutes).format("YYYY-MM-DD");
console.log(currentDate) // 2022-05-13
console.log(moment(currentDate).format("dddd")); // "Sunday" ????
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.3/moment.min.js"></script>