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

250
Views
Converting Unix timestamp to date time - different results for JS and Python

I have sqlite log file where date is in timestamp.

The conversion with JS by following function gives the correct result

var unixTsToDate = function (UNIX_Timestamp){
var date = new Date(UNIX_Timestamp / 1000);
return date;
};

unixTsToDate (1615370972685000) = Wed Mar 10 2021 11:09:32 GMT+0100

Now I'm trying to to the same with Python 3.9 and it aborts with Error

import datetime
print(datetime.datetime.utcfromtimestamp(1615370972685000))

result:
print(datetime.datetime.utcfromtimestamp(1615370972685000))
OSError: [Errno 22] Invalid argument

The number seems too big for the function. Tried with /1000 (found in internet that could be different timestamps with milliseconds and without), no result

What could be a solution for Python in the case?

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

0

Your timestamp value has microsecond resolution.

51 years (since epoch) * 365 * 24 * 3600 will give roughly 1.6 billion seconds. Your value has additional 6 digits.

So in Python divide by 1000000 instead of 1000.

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!