How to work with a Javascript +Date() numeric time stamp in Python?

Rahul

I've a JavaScript date string which I want to convert in understandable form. E.g.

new Date(1415988000000)

which gives the output

Fri Nov 14 2014 23:30:00 GMT+0530 (IST)

I want to do this in python. I don't want to use PyV8. Is there any other alternative ?

Paul

You don't need to write Javascript in Python to convert the timestamps.

The following works in pure python.

Note:

  • The JS Date format is the number of milliseconds since Jan 1,1970 UTC.
  • Oddly enough, the python format for time.time() is the number of seconds since Jan 1, 1970 UTC.

This standard is sometimes called Unix time

First, for the milliseconds to seconds time conversion, you need to divide 1415988000000 by 1000, obtaining 1415988000

Then you can use the datetime library like this:

import datetime
d = datetime.datetime.fromtimestamp(1415988000)
print d

Obtaining:

2014-11-14 13:00:00

This print seems to have converted d to my TZ which is UTC-5.

So UTC time would be 18:00.

This explains the later time, 23:30, you receive in JS for the same stamp in IST or UTC+5:30

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

how do i convert unix time stamp to formatted date while using json_extract_scalar in bigquery

分類Dev

How to add 3 months to a UTC time stamp in javascript centered at midnight 00 Hours?

分類Dev

How to log Serial data with time stamp?

分類Dev

How to stamp prompt at command execute time?

分類Dev

How is the time stamp number in /etc/shadow calculated?

分類Dev

How can I check date and time on javascript?

分類Dev

How to compare current time only without date to a given time in javascript

分類Dev

How to get current date time in python flask

分類Dev

how to convert python time.time() to date format for sql insertion

分類Dev

Getting date time stamp difference minutes in Oracle Database 12c Enterprise Edition

分類Dev

Code for automatically entering date/time stamp into cell based upon table heading

分類Dev

Can the time stamp of a Retweet be accessed?

分類Dev

How to check a date time column in a specific range in python panda?

分類Dev

How to add date column to already existing time column in python?

分類Dev

How to calculate date time values over python list items

分類Dev

Getting epoch time from gmt time stamp

分類Dev

Javascript Date() object with NULL Time

分類Dev

Date and time without timestamp in Javascript

分類Dev

How to find time stamp and decimal value reading from data stream in Java

分類Dev

how to tell rsync to preserve time stamp on files when source tree has a mounted point

分類Dev

python pandas quantlib.time.date.Date

分類Dev

Javascript: how to create an object with numeric String keys

分類Dev

Javascript how do sum class numeric value?

分類Dev

remove specific characters from time stamp

分類Dev

pulling a time stamp from a txt file

分類Dev

Cassandra time stamp returns 0 rows

分類Dev

How to convert this STRING into time + date

分類Dev

How to remove the time out of this date?

分類Dev

How to insert time into a DATE type?

Related 関連記事

  1. 1

    how do i convert unix time stamp to formatted date while using json_extract_scalar in bigquery

  2. 2

    How to add 3 months to a UTC time stamp in javascript centered at midnight 00 Hours?

  3. 3

    How to log Serial data with time stamp?

  4. 4

    How to stamp prompt at command execute time?

  5. 5

    How is the time stamp number in /etc/shadow calculated?

  6. 6

    How can I check date and time on javascript?

  7. 7

    How to compare current time only without date to a given time in javascript

  8. 8

    How to get current date time in python flask

  9. 9

    how to convert python time.time() to date format for sql insertion

  10. 10

    Getting date time stamp difference minutes in Oracle Database 12c Enterprise Edition

  11. 11

    Code for automatically entering date/time stamp into cell based upon table heading

  12. 12

    Can the time stamp of a Retweet be accessed?

  13. 13

    How to check a date time column in a specific range in python panda?

  14. 14

    How to add date column to already existing time column in python?

  15. 15

    How to calculate date time values over python list items

  16. 16

    Getting epoch time from gmt time stamp

  17. 17

    Javascript Date() object with NULL Time

  18. 18

    Date and time without timestamp in Javascript

  19. 19

    How to find time stamp and decimal value reading from data stream in Java

  20. 20

    how to tell rsync to preserve time stamp on files when source tree has a mounted point

  21. 21

    python pandas quantlib.time.date.Date

  22. 22

    Javascript: how to create an object with numeric String keys

  23. 23

    Javascript how do sum class numeric value?

  24. 24

    remove specific characters from time stamp

  25. 25

    pulling a time stamp from a txt file

  26. 26

    Cassandra time stamp returns 0 rows

  27. 27

    How to convert this STRING into time + date

  28. 28

    How to remove the time out of this date?

  29. 29

    How to insert time into a DATE type?

ホットタグ

アーカイブ