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

  • Home
  • SEARCH
  • 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 7870049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:30:09+00:00 2026-06-03T01:30:09+00:00

To get timestamp in JavaScript we use var ts = new Date().getTime() What is

  • 0

To get timestamp in JavaScript we use

var ts = new Date().getTime()

What is the proper way to convert it to a Python datetime so far I use the following code

>>> jsts = 1335205804950
>>> dt = datetime.datetime.fromtimestamp(jsts/1000)
>>> dt
datetime.datetime(2012, 4, 24, 0, 30, 4)

I divide timestamp by 1000 because I get error like

ValueError                                Traceback (most recent call last)
1 d = datetime.datetime.fromtimestamp(a)
ValueError: year is out of range
  • 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-06-03T01:30:11+00:00Added an answer on June 3, 2026 at 1:30 am

    Your current method is correct, dividing by 1000 is necessary because your JavaScript returns the timestamp in milliseconds, and datetime.datetime.fromtimestamp() expects a timestamp in seconds.

    To preserve the millisecond accuracy you can divide by 1000.0, so you are using float division instead of integer division:

    >>> dt = datetime.datetime.fromtimestamp(jsts/1000.0)
    >>> dt
    datetime.datetime(2012, 4, 23, 11, 30, 4, 950000)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following javascript code gives me output like : 1314066350368 new Date().getTime(); I would like
Alright when I do the code: <script type = text/javascript > document.write((new Date).getTime()); </script>
is there an easy way to get the unix timestamp in javascript from a
I'm using the following code to get a timestamp in Javascript, but it's returning
Possible Duplicate: How do you get a timestamp in JavaScript? Calculating milliseconds from epoch
I need to convert a date in format eg. 2011-01-02 to a unix timestamp
How do I get the day of the week from a timestamp in JavaScript?
How do you get a timestamp from a file with SQL Server Intergration Services
In MySQL, how would I get a timestamp from, say 30 days ago? Something
Any idea in PHP how to get a unix timestamp of the next occurring

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.