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

169
Views
¿Cómo separar la fecha, la hora y el día con el título en el código nativo de reacción?

El formato de fecha y hora de mi API es así: ingrese la descripción de la imagen aquí

Actualmente estoy usando este método para representar la fecha y la hora en mi código. ingrese la descripción de la imagen aquí

 let d = new Date(item.starts_on); let date = `${d.getMonth() + 1}/${d.getDate()}/${d.getFullYear()}`; let time = `${d.getHours()}:${d.getMinutes()}`;

Pero quiero renderizarlo en este formato. ingrese la descripción de la imagen aquí Por favor ayúdame

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

0

Hay dos enfoques para hacerlo, la primera forma (que es más fácil) usando paquetes como moment o dayjs al usarlo, puede manejar la fecha y convertirla en muchas formas diferentes (para obtener más información, consulte los documentos de ellos). Por ejemplo, si desea separar la fecha y la hora de una marca de tiempo, puede hacerlo por momento como se muestra a continuación:

 /* other your imports and codes */ let timestamp = moment(item.starts_on); let date = timestamp.format('L'); let time = timestamp.format('LT'); /* other your codes */

La segunda forma es usar una instancia de Date , para hacerlo puedes:

 /* other your imports and codes */ let d = new Date(item.starts_on); let date = `${d.getMonth() + 1}/${d.getDate()}/${d.getFullYear()}`; let time = `${d.getHours()}:${d.getMinutes()}`; /* other your codes */

Respuesta de actualización Para convertir la fecha a "Sábado 19 de marzo de 2022" que desee, siga a continuación:

 //fill in Months array const Months = ["Jan", "Feb", ..., "Dec"]; //fill in Days of week array const Days = ["Sun", "Mon", ..., "Sat"]; /* other your codes */ let d = new Date(item.starts_on); let monthIndex = d.getMonth(); let month = Months[monthIndex]; let dayIndex = d.getDay(); let day = Days[dayIndex]; let date = `${day} ${d.getDate()} ${month} ${d.getFullYear()}`; /* other your codes */
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!