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

79
Visualizações
How do I convert year to seconds?

I will prompt the user to enter the years he lived then it should return the seconds he lived.

The code:

let use = prompt("Enter number of years u lived: ");
let u = parseInt(use)
let time = new Date() 
let compute = time.getFullYear() - u



console.log(compute.getSeconds()+time.getFullYear());

But I get an error that says 'Uncaught TypeError: compute.getSeconds is not a function'

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

0

Assuming an approximation is fine (because you're not asking for a birth date anyway), it might be the easiest to just multiply the number by the number of seconds per year.

const seconds = years * 60 * 60 * 24 * 365;

This is not exact because it's not accounting for leap day and leap second rules.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can just do it the naive way:- multiply the year by '31,536,000'. But this will lack accuracy.

about 4 years ago · Juan Pablo Isaza Relatório

0

You're assigning compute an integer value by using getFullYear(). That's why you're getting a TypeError.

To calculate the number of seconds lived you can do what Evert suggests in his answer.

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