I have next time value in unicode (<type 'unicode'>
):
2017-08-09T15:02:58+0000
.
How to convert it to friendly view (e.g. Day, Month of Year
)?
I have next time value in unicode (<type 'unicode'>
):
2017-08-09T15:02:58+0000
.
How to convert it to friendly view (e.g. Day, Month of Year
)?
This should do what you ask:
from datetime import datetime
a = '2017-08-09T15:02:58+0000'
datetime.strptime(a[:-5], '%Y-%m-%dT%H:%M:%S').strftime('%d, %b of %Y')
#09, Aug of 2017
strptime
method throws error for timezone parameter that doesn't seem to interest you so I removed that part with a[:-5]
.
For the rest of the string you can just follow guidelines from datetime docs.
Using the same docs you can construct your datetime
string using strftime()
method like you wanted '%d, %b of %Y'
or in plain words [day], [abbreviated month] of [Year]
try this
import datetime
today = datetime.date.today()
print today.strftime('We are the %d, %b %Y')
'We are the 22, Nov 2008'