Parsing a Python date and time string in Javascript

I need to parse the date and time string generated by Python into a Date Javascript object. I drove the easiest route:

In Python:

dstring = str(mydate) 

example dstring = '2012-05-16 19: 20: 35.243710-04: 00'

In Javascript (with datejs library):

 d = new Date(dstring); 

This gives me the correct date object in Chrome, but the "Invalid Date" error in Firefox and Safari (on Mac).

+4
source share
1 answer

You need to parse the string in JS Date. The Date constructor is not enough. Maybe you should use a library like datejs:

http://www.datejs.com/

Datejs extends the Date object with useful methods such as:

 Date.parse('Thu, 1 July 2004 22:30:00'); 

Needless to say, date / time formats are customizable.

+1
source

Source: https://habr.com/ru/post/1412883/


All Articles