Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

76
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!