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

147
Visualizações
In react, I get too similar unix time stamp in <TextField type="date">

I have two Textfield which set the start date and due date.

here is the code.

const startDateChange = (e) => {
  setStartDate(Math.floor(new Date().getTime(e.target.value) / 1000));
  console.log(startDate);
};

const dueDateChange = (e) => {
  setDueDate(Math.floor(new Date().getTime(e.target.value) / 1000));
  console.log(dueDate);
};

<div>
  <Typography variant="overline" display="block" gutterBottom>Start Date</Typography>
  <TextField id="standard-basic" type='date' style={{margin:3}} onChange={startDateChange} />
</div>
<div>
  <Typography variant="overline" display="block" gutterBottom>Due Date</Typography>
  <TextField id="standard-basic" type='date' style={{margin:3}} onChange={dueDateChange} />
</div>

However, every time I change these two individual inputs, I always get similar numbers (Unix timestamp), even I set the due date as the year 2033.

Therefore, When I render with converted Unix timestamp number, I get the same date of each of these two inputs, which are the date of Today.

I need bits of help.

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

0

Try to move the e.target.value in the Date constructor:

const startDateChange = (e) => {
  setStartDate(Math.floor(new Date(e.target.value).getTime() / 1000));
  console.log(startDate);
};

const dueDateChange = (e) => {
  setDueDate(Math.floor(new Date(e.target.value).getTime() / 1000));
  console.log(dueDate);
};
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