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

1.2K
Views
Compute Date out of Timestamp from Binance-API (Python)

I received the servertime from the Binance-API,I try to work with and it looks like this:

{
  "serverTime": 1518440400000
}

The question is, how can I compute the date out of this stamp?

I tried

import datetime

print(datetime.datetime.fromtimestamp(
       int("1518308894652")).strftime('%Y-%m-%d %H:%M:%S'))

But the date wasn´t valid.

Do you have ideas, or is it to specific? Thank you!

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You could use this:

from datetime import datetime
datetime.fromtimestamp(int("1518308894652"))

But python says the year is out of range (understandably, considering it says it's 50087). So I suspect that serverTime is not a normal timestamp.

But assuming the response that you got was the timestamp, so you don't need to do any other conversions other than turning the string into an int.

Edit:

Turns out the docs say "All time and timestamp related fields are in milliseconds." So just divide the response by 1000 and you'll be fine: datetime.fromtimestamp(int("1518308894652")/1000). Source

over 4 years ago · Santiago Trujillo Report

0

Your response is in milliseconds when datetime.fromtimestamp requires seconds.

import datetime

print(datetime.datetime.fromtimestamp(1518308894652/1000))

# 2018-02-10 19:28:14.652000
over 4 years ago · Santiago Trujillo Report

0

Pandas can handle this perfectly by specifying miliseconds as the unit.

import pandas as pd
pd.to_datetime(1518440400000, unit='ms')

Timestamp('2018-02-12 13:00:00')

over 4 years ago · Santiago Trujillo 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!