[英]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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.