1import datetime
2
3date_time_str = '2018-06-29 08:15:27.243860'
4date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S.%f')
5
6print('Date:', date_time_obj.date())
7print('Time:', date_time_obj.time())
8print('Date-time:', date_time_obj)
9
1import datetime
2
3today = datetime.datetime.now()
4date_time = today.strftime("%m/%d/%Y, %H:%M:%S")
5print("date and time:",date_time)
1from datetime import datetime
2
3datetime_object = datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p')
1"Jun 28 2018 at 7:40AM" -> "%b %d %Y at %I:%M%p"
2"September 18, 2017, 22:19:55" -> "%B %d, %Y, %H:%M:%S"
3"Sun,05/12/99,12:30PM" -> "%a,%d/%m/%y,%I:%M%p"
4"Mon, 21 March, 2015" -> "%a, %d %B, %Y"
5"2018-03-12T10:12:45Z" -> "%Y-%m-%dT%H:%M:%SZ"
6
1import datetime
2
3print ('Current date/time: {}'.format(datetime.datetime.now()))