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

139
Views
Salida el día de la semana, me entrega 2x el mismo día

Quiero mostrar los días de la semana en función de los días de un mes. Ahora bien, sucede que el domingo siempre se cuenta dos veces. Sin embargo, cuando abro el depurador y establezco un punto de interrupción en el ciclo for, el "0" para el domingo solo se cuenta una vez. Cómo es eso ?

ingrese la descripción de la imagen aquí

 function getDayName(dateStr, locale) { var date = new Date(dateStr); return date.toLocaleDateString(locale, { weekday: "long" }); } const Items = () => { let array = []; const d = new Date(); let tageImMonat = daysInMonth(d.getMonth() + 1, d.getFullYear()); for (var i = 1; i <= tageImMonat; i++) { var newDate = new Date(d.getFullYear(), d.getMonth(), i); var day = getDayName(newDate, "de-DE"); if (newDate.getDay() === 0) { //if Sunday array.push( <Item sx={{ backgroundColor: "red", textAlign: "left" }}> {i} {day} </Item> ); } if (newDate.getDay() === 6) { //if Saturday array.push( <Item sx={{ backgroundColor: "lightgrey", textAlign: "left" }}> {i} {day} </Item> ); } else if (newDate.getDay() !== 0 || newDate.getDay() !== 6) { array.push( <Item sx={{ textAlign: "left" }}> {i} {day} </Item> ); } } return array; };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Prueba así:

 function getDayName(dateStr, locale) { var date = new Date(dateStr); return date.toLocaleDateString(locale, { weekday: "long" }); } function Items() { const array = []; const d = new Date(); const tageImMonat = daysInMonth(d.getMonth() + 1, d.getFullYear()); for (let i = 1; i <= tageImMonat; i++) { const newDate = new Date(d.getFullYear(), d.getMonth(), i); const day = getDayName(newDate, "de-DE"); switch (newDate.getDay()) { case 0: //if Sunday array.push( <Item sx={{ backgroundColor: "red", textAlign: "left" }}> {i} {day} </Item> ); break; case 6: //if Saturday array.push( <Item sx={{ backgroundColor: "lightgrey", textAlign: "left" }}> {i} {day} </Item> ); break; default: array.push( <Item sx={{ textAlign: "left" }}> {i} {day} </Item> ); } } return array; }
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!