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

150
Visualizações
Compare current time with a specific time in a if statement

I'm trying to compare the current time with a specific time in React Native by using JavaScript but it's not working with this method that i have tried. This is how i have tried it:

export default function SettingsComponent() {
  let today = new Date();
  let currentTime = today.toLocaleTimeString();

  useEffect(() => {
    console.log(currentTime)
    if(currentTime == "12:39:30"){
      console.log('Comparison is working')
    }
  })
}

If there are any other suggestions to do this, let me know!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can make this work by passing argument(s) to toLocalTimeString so to guarantee the format you get from it. For instance, you could specify a locale that uses the hh:mm:ss format:

today.toLocaleTimeString("en-SE")

Secondly, you should realise that you only have 1 second to have a match. One can imagine how some latency can make you miss a match, and the code only gets executed just after that second passed.

about 4 years ago · Juan Pablo Isaza Relatório

0

Likely your useEffect is running before the currentTime is set. Try adding the currentTime to the useEffects dependency array.

    useEffect(() => {
        console.log(currentTime)
        if(currentTime == "12:39:30"){
          console.log('Comparison is working')
        }
      }, [currentTime])
about 4 years ago · Juan Pablo Isaza Relatório
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