Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading