How to compare Python DateTime with Javascript DateTime?

The datetime in Javascript and in Python have 2 major differences. First one being the meaning of the month argument.

The month in Javascript is expected between 0-11 while in Python it is expected to be between 1-12. So the following tuple actually represents 2 different dates in Python and in Javascript −

(2017, 11, 1)
Python: 1st November 2017
Javascript: 1sd December 2017

The second difference is that they have different default timezones, with Python defaulting to UTC while JavaScript defaults to the user's "local" timezone. You can use Date.UTC(), which returns the timestamp, for the equivalent in JavaScript. For example,

var utc = Date.UTC(2013, 7, 10);

Updated on: 12-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started