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

142
Visualizações
Convert Material-UI DatePicker value to seconds

React Material-Ui datepicker currently gives me value like this: 2021-05-26T01:30 How can I convert it to seconds?

PS: I am building a schedule SMS module. So my plan is to convert the selected date into seconds so that I can then use setTimeOut() to send the SMS when the day & time arrives.

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

0

If you want to use setTimeOut, you need to:

  1. Compute the difference between the date chosen in the date picker and the current date. This will give you a duration.
  2. Convert the duration into millisecond as the delay for setTimeOut is specified in milliseconds

To do so the easiest way is probably to use dayjs, which is a lightweight package to handle Date & Time operations. It works well with react because it is immutable.

Using dayjs.diff you can compute the duration in milliseconds directly like so : const durationInMs = daysj("2021-05-26T01:30").diff(dayjs())

note: By default dayjs parses datetime in local time

Edit

You can also use the Native Date Constructor directl, here's an example from the docs:


// Using built-in methods
let start = new Date()
let end = new Date("2021-05-26T01:30")

let elapsed = end.getTime() - start.getTime() // elapsed time in milliseconds
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