Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
How to validation time 12 hour for onTextChange at TextInput in React-Native

I have a TextInput and its placeholder in 12 hours (00:00) format with no AM or PM suffix, and I want when the user finishes typing the time, it automatically adds a ':' character after I enter the hours time. then I keep entering the number of minutes, and while the user enters the number of hours greater than 12, it automatically converts the hour to the 12-hour format, for example, if the user enters 13 it should automatically change back to 01 and then add the character ':' after.

Ex: 02 -> 02:xx,

15 -> 03:xx

Below is my code


const [times, setTime] = useState('');

const convertTime12Hours = (time12h) => {
    const time = time12h.split(' ');

    let [hours, minutes] = time.split(':');

    if (hours >= '12') {
        hours = hours % 12;
    }
    setTime(`${hours}:${minutes}`);
};

<TextInput
    value={times}
    style={styles.text_input}
    onChangeText={(value) => {
        convertTime12Hours(value);
    }}
    placeholder='00:00'
/>;

Please, Hope you guys can help me.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda