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

127
Visualizações
Is it possible to get a date object out of milliseconds in javascript

I know that a sample date object in javascript is constructed from a string containing the year, month and day. I am building a function that takes a date and number of days as arguments and adds the days to the date and returns a new date object from the same. The approach i used is this:

a) Get the milliseconds from the date object

b) Convert the days to milliseconds

c) Add the two and then derive a date object from the resultant sum. I need a way to get back to the date from the milliseconds. Thank You for your help

function AddDays(x,y){
    //convert the days to milliseconds
    let days_milli=y*24*60*60*1000;
    //get the time in millis from the date
    let days_millis=x.getTime();
    //add the times
    let total=days_milli+days_millis;
    //construct a date object from that
     //this line needs some help
    let date=getDate(total);
    return date;
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Looks like the Date class constructor has overloads to support construction of objects from a string and milliseconds. All i needed to do was to invoke new Date and then put the milliseconds in the parameter part.

function AddDays(x,y){
    //convert the days to milliseconds
    let days_milli=y*24*60*60*1000;
    //get the time in millis from the datw
    let days_millis=x.getTime();
    //add the times
    let total=days_milli+days_millis;
    //construct a date object from that
    let date=new Date(total);
    return 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