How to parse JSON datetime string in python?
json, python
Solution
You should get unix timestamp with a regex from this date, then use datetime module to convert it to readable format:
>m = re.search(r"Date\((\d+)\+", 'Date(1354011247940+0000)')
>print(datetime.datetime.fromtimestamp(int(m.group(1))/1000.0).strftime('%Y-%m-%d %H:%M:%S'))
2012-11-27 12:14:07
UPD: note , that you also have milliseconds in this date, they will be truncated by this code
Problem
From python I am making a call to a remote API which returns data in a JSON format. I then parse the data using the json module with json.loads(). The problem I am having is with dates - the system I am calling returns the date formatted like the following: ``` /Date(1354011247940+0000)/ ``` which json.parse just parses out as a string. How can I convert this to a python date time object? Edit: unlike Convert JSON to Python object: how to handle DateTime conversion?, I have no control over the data being sent, so I can not simply change the format prior to serializing.