-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrptime_strftime.py
More file actions
24 lines (19 loc) · 876 Bytes
/
Copy pathstrptime_strftime.py
File metadata and controls
24 lines (19 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'''
Shows the differences between 'strptime' and 'strftime' from 'datetime' and 'time' modules
'''
import datetime
import time
dateA = datetime.datetime.now()
print(type(dateA), dateA)
# Convert datetime to str - Return a string representing the date, controlled by an explicit format string.
dateB = dateA.strftime('%m/%d/%Y')
print(type(dateB), dateB)
# Convert str to datetime - Return a datetime corresponding to date_string, parsed according to format.
dateC = datetime.datetime.strptime(dateB,'%m/%d/%Y')
print(type(dateC), dateC)
# Convert str to struct_time - Parse a string to a time tuple according to a format specification.
dateD = time.strptime(dateB,'%m/%d/%Y')
print(type(dateD), dateD)
# Convert struct_time to str - Convert a time tuple to a string according to a format specification.
dateE = time.strftime('%m/%d/%Y')
print(type(dateE), dateE)