python - Convert the unicode to datetime format -
a function returns date , time in unicode format.
u'2014-03-06t04:38:51z'
i wish convert date , time format , subtract current datetime number of days in between.
thanks in advance
check string unicode
>>> import types >>> type(u'2014-03-06t04:38:51z') types.unicodetype true
converting strings datetime:
>>> import datetime >>> datetime.datetime.strptime(u'2014-03-06t04:38:51z', '%y-%m-%dt%h:%m:%sz') datetime.datetime(2014, 3, 6, 4, 38, 51)
subtract today
>>> import datetime >>> today = datetime.datetime.today() >>> yourdate = datetime.datetime.strptime(u'2014-03-06t04:38:51z', '%y-%m-%dt%h:%m:%sz') >>> difference = today - yourdate print str(difference)
Comments
Post a Comment