
From string to convert date time in python
1 2 3 4 5 6 7 8 9 |
from datetime import date from datetime import time from datetime import datetime string_date = "2018-05-20 10:10:55.78200" print(string_date) print(type(string_date)) string_date = datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S.%f") print(string_date) print(type(string_date)) |
Result:
1 2 3 4 |
2018-05-20 10:10:55.78200 <type 'str'> 2018-05-20 10:10:55.782000 <type 'datetime.datetime'> |
Now if you want to represent your desire date like Sun May 20 10:10:55 2018
1 |
print(string_date.strftime("%c")) |