Converting GMT to desired date and time format
First, you need to convert the string to a datetime object using strptime
Then convert back in the desired string format using strftime
Complete code:
Output : '2018/03/14'
First, you need to convert the string to a datetime object using strptime
dt = datetime.datetime.strptime('Wed, 14 Mar 2018 07:30:00 GMT','%a, %d %b %Y %H:%M:%S %Z')
Then convert back in the desired string format using strftime
dt.strftime('%Y/%m/%d')
Complete code:
import datetime dt = datetime.datetime.strptime('Wed, 14 Mar 2018 07:30:00 GMT', '%a, %d %b %Y %H:%M:%S %Z') print dt.strftime('%Y/%m/%d')
Output : '2018/03/14'
Comments
Post a Comment