Apr-15-2018, 03:12 PM
Hi,
I am parsing a json file and the string it returns the date as looks like this:
'2018-03-31T00:19:38Z'
This is ISO 8601 format. I have looked at various libraries to try to parse this and have gotten nothing to work.
I wrote some code that turns that into 2018-03-31. However that is still a string and for the functions I want to use in datetime I need to pass it a number.
This is what my code looks like now
I am parsing a json file and the string it returns the date as looks like this:
'2018-03-31T00:19:38Z'
This is ISO 8601 format. I have looked at various libraries to try to parse this and have gotten nothing to work.
I wrote some code that turns that into 2018-03-31. However that is still a string and for the functions I want to use in datetime I need to pass it a number.
This is what my code looks like now
from collections import Counter import json import datetime import dateutil.parser #List & json file stuffs mylist = [] with open ('dates.txt') as a: data = json.load(a) #Loop, count & clean for dat in range(len(data)): test = (data[dat].get('commit').get('author').get('date')) test2 = test[:-10] #test3 = test2.replace("-", ", ") #datetime.date(2010, 6, 16).isocalendar()[1] # yourdate = dateutil.parser.parse(test, ignoretz=True) # new = datetime.date(yourdate) mylist.append(test) #Show me the money print (mylist)There is other code commented out from other things I have tried.