Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:13:35+00:00 2026-05-31T13:13:35+00:00

I have a data file containing timestamps like 1331856000000. Unfortunately, I don’t have a

  • 0

I have a data file containing timestamps like “1331856000000”. Unfortunately, I don’t have a lot of documentation for the format, so I’m not sure how the timestamp is formatted. I’ve tried Python’s standard datetime.fromordinal() and datetime.fromtimestamp() and a few others, but nothing matches. I’m pretty sure that particular number corresponds to the current date (e.g. 2012-3-16), but not much more.

How do I convert this number to a datetime?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:13:35+00:00Added an answer on May 31, 2026 at 1:13 pm

    datetime.datetime.fromtimestamp() is correct, except you are probably having timestamp in miliseconds (like in JavaScript), but fromtimestamp() expects Unix timestamp, in seconds.

    Do it like that:

    >>> import datetime
    >>> your_timestamp = 1331856000000
    >>> date = datetime.datetime.fromtimestamp(your_timestamp / 1e3)
    

    and the result is:

    >>> date
    datetime.datetime(2012, 3, 16, 1, 0)
    

    Does it answer your question?

    EDIT: jfs correctly suggested in a now-deleted comment to use true division by 1e3 (float 1000). The difference is significant, if you would like to get precise results, thus I changed my answer. The difference results from the default behaviour of Python 2.x, which always returns int when dividing (using / operator) int by int (this is called floor division). By replacing the divisor 1000 (being an int) with the 1e3 divisor (being representation of 1000 as float) or with float(1000) (or 1000. etc.), the division becomes true division. Python 2.x returns float when dividing int by float, float by int, float by float etc. And when there is some fractional part in the timestamp passed to fromtimestamp() method, this method’s result also contains information about that fractional part (as the number of microseconds).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a .txt file containing data like: He: 22.1 Ar: 21.1 K: 1.22
I have a text file containing the data in following format 12345 Abdt3 hy45d
I have a file containing a [Double] serialized by Data.Binary that I'd like to
I have a file containing data like below: 88_NPDJ 565 789 3434 54454 98HGJDN
I have a text file containing data like this: This is just text -------------------------------
I have a file containing data like so: 2012-01-02 GREEN 4 2012-01-02 GREEN 6
I have a file containing data that I'd like to monitor changes to, as
I have a data file containing a combination of doubles and strings like this:
I have file containing data like: 12, 9 13, 9 45, 23 1, 4
I have a CSV file containing log on data for users and would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.