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

228
Views
Javascript Date object keeps on returning the default date (Mon Jan 19 1970 19:18:18) when trying to convert unix time

I am trying to use the date function to convert unix time that I am trying to convert to a certain format. The function successfully returns the date in the format requested, but the time is wrong. What am I missing here?

const date = (e) => { 
  const unixTime = 1642698000
  const format = {
    weekday: 'long',
    day: 'numeric', 
    month: "2-digit", 
    year: "numeric"
  }
  return(new Date (unixTime).toLocaleString('en-US', format))
}

Expected output (app.)

Tue Jan 18 2022 17:00:00

The output recieved

Mon Jan 19 1970 19:18:18 GMT-0500 (Eastern Standard Time)

I tried following other exampled but I wasn't able to find any that would resolve this issue. I appreciate your help in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The Date constructor from Javascript accepts the number of milliseconds as timestamp, not unix time (number of seconds). So, to adjust that, is just multiply the unix time by 1000.

const date = () => { 
  const unixTime = 1642698000 * 1000
  const format = {
    weekday: 'long',
    day: 'numeric', 
    month: "2-digit", 
    year: "numeric"
  }
  return(new Date (unixTime).toLocaleString('en-US', format))
}

console.log(date())
// logs Thursday, 01/20/2022
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!