Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
Moment JS Wrong Date

let time = moment();

console.log(
  time
  .year(2021)
  .week(34)
  .day('monday')
  .format('D MMM YYYY'),
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

Displays 16 Aug 2021 but it should be 23 Aug 2021 - why?

Works well if the year is 2020, 2019, etc but fails on year 2021

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Switch .week to .isoWeek and it works.

const moment = require("moment");

let time = moment();

console.log(
  time
    .year(2021)
    .isoWeek(34)
    .day('monday')
    .format('D MMM YYYY'),
);

More info from this answer https://stackoverflow.com/a/68842658/6254964

about 4 years ago · Juan Pablo Isaza Report

0

It is not wrong. If you look at the 2021 calendar, the 34th week is 15 - 21 August. You specified it as Monday.So it's 16 Aug 2021.

Note: Start of a week is Sunday (ISO Standard).

about 4 years ago · Juan Pablo Isaza Report

0

It might be because of your locale. the week method uses your locale to determine which week is the first of the year (which would mess up your week calculation, putting you one week behind).

For more, read here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!