Im using https://openweathermap.org/ api. It provides timezone in seconds. How to properly get day of the week (name) using 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" ????
CodePudding user response:
You are putting currentDate
into day()
, you need to put it on 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>