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

226
Views
¿Cómo cambiar el formato de la hora?

Tengo una entrada de tipo tiempo, cuando hago clic en ella puedo seleccionar una hora de 1 a 12, minutos y AM/PM. instantánea

Cuando renderizo la selección, aparece en formato de 24 horas. Sin embargo, en cambio, quiero que esté en un formato de 12 horas.
Estoy trabajando en una aplicación react-redux.

 <input type='time' onChange={(e) => this.setState({ time: e.target.value })} value={this.state.time} />
 state = { time: '' } render = () => { return ( <span>{time}</span> ) }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

puede usar esta función para cambiar el formato de hora:

 const timeConvertor = (time) => { // first checks the correct time format and then split it into components time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time]; if (time.length > 1) { // If the time format is correct time = time.slice (1); // Remove full string match value time[5] = +time[0] < 12 ? 'AM' : 'PM'; // Set AM/PM based on given hour time[0] = +time[0] % 12 || 12; // change the hour based on AM/PM } return time.join (''); // return new time format as a String }

por ejemplo:

 timeConvertor('20:50:00'); // will return '8:50:00PM'
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!