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

179
Views
Configuración del formato de entrada de tiempo en Frontend

Estoy tratando de modificar el siguiente código en React Typescript. Quiero devolver el valor de entrada en formato de hora como - "Jue 01 de enero de 2022 13:03:00 GMT-0500 (hora estándar del este)" ¿alguna sugerencia sobre cómo hacerlo?

Código completo: https://codepen.io/dcode-software/pen/jOwVqGO

 function getTimeStringFromPicker(timePicker) { const selects = getSelectsFromPicker(timePicker); return `${selects.hour.value}:${selects.minute.value} ${selects.meridiem.value}`; } function numberToOption(number) { const padded = number.toString().padStart(2, "0"); return `<option value="${padded}">${padded}</option>`; } activate();
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede crear un nuevo objeto Date y establecer las horas y los minutos en él. A partir de ahí, puedes convertirlo en una cadena. Como esto:

 function getTimeStringFromPicker(timePicker) { const selects = getSelectsFromPicker(timePicker); const d = new Date(); d.setMinutes(selects.minute.value); // setHours takes in hours in 24hr format if (selects.meridiem.value === "pm") { d.setHours(selects.hour.value + 12); } else { d.setHours(selects.hour.value); } return d.toString(); }

Si esto soluciona tu problema, puedes marcarlo como correcto.

about 4 years ago · Santiago Trujillo Report

0

Si puede llegar a un objeto Date de alguna manera, su método toLocaleString() puede hacer algo así (los parámetros reales se describen aquí .

 let date = new Date(); console.log(date.toLocaleString("en-US", { timeZone: "EST", dateStyle: 'full', timeStyle: 'full', hour12: false // this is because you seem to want a 24-hour format }));

Si necesita más, moment.js podría ser una biblioteca para consultar.

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