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

269
Visualizações
JS: convert time to a Date format

What's the right way to convert time in string format to the current Date? I'm using Moment

Expected: "15:00" -> Sat Mar 19 2022 15:00:00 "11:00" -> Sat Mar 19 2022 11:00:00

The output should be the current date and specified time. For example, if today is Mar 19 and the string time is 15:00, it should Sat Mar 19 2022 15:00:00

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

0

You can use moment's format method, to format the output according to your needs.

More about formatting options - https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/

var t = "15:00";
var cdt = moment(t, 'HH:mm');

console.log(cdt.format('ddd MMM D Y HH:mm:ss'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

about 4 years ago · Juan Pablo Isaza Relatório

0

I think that it could be tricky just with hour as your string because you still need to provide information for the rest of the parameters that you could try when you have this string you create a variable for Date in needed style and then set hours to string you have. But if you using moment then just extend the format in which you are getting your time and you won't have to use Date

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