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

163
Views
Formato JS 201708 en formato Myyy

Tengo una cadena en este formato 201708 donde los primeros cuatro números son el año y los dos últimos el mes. El resultado es una fecha de agosto de 2017.

Mi primera idea fue simplemente llegar a una cita, pero no funciona para mí.

 var formattedDate = new Date("201708")

Gracias por cualquier ayuda

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Separe la fecha con un guión.

 let b = "201708" let b_with_hyphen = b.substring(0, 4) + "-" + b.slice(4) // '2017-08' let formattedDate = new Date(b_with_hyphen) console.log(formattedDate.toUTCString())

about 4 years ago · Santiago Gelvez Report

0

use substring() para dividir la cadena en año y mes, luego utilícelos cuando llame a Date() .

 let input = '201708'; let year = parseInt(input.substring(0, 4)); let month = parseInt(input.substring(5)); let date = new Date(year, month-1); console.log(date);

Tienes que restar 1 del month porque JS cuenta los meses a partir de 0 .

about 4 years ago · Santiago Gelvez 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!