'how to properly get day of the week (name) with moment.js?
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" ????
Solution 1:[1]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Pipe |