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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

angularjs - ng-repeat duplicating items after page reload -