-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path63-Time Module.py
More file actions
36 lines (27 loc) · 1.78 KB
/
63-Time Module.py
File metadata and controls
36 lines (27 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# **********************************************************************************************************************
import time
# **********************************************************************************************************************
print(time.ctime(0)) # convert a time expressed in seconds since epoch to a readable string
# epoch = when your computer thinks time began (reference point)
print(time.time()) # return current seconds since epoch
print("===============================================================================================================")
print(time.ctime(time.time())) # return current date and time in readable format
time_obj = time.localtime() # creates a time object
time_utc = time.gmtime() # UTC
print(time_obj) # just to show how the time object is formatted
local_time = time.strftime("%B %d %Y %H:%M:%S", time_obj) # format, time_object
print(local_time)
print("===============================================================================================================")
time_string = "31 July, 2022"
time_objstr = time.strptime(time_string, "%d %B, %Y")
print(time_objstr)
print("===============================================================================================================")
# (year, month, day, hours, minutes, secs, #day of the week, #day of the year, dst)
time_tuple = (2022, 4, 20, 4, 20, 0, 0, 0, 0)
time_tupstr = time.asctime(time_tuple)
print(time_tupstr)
print("===============================================================================================================")
# (year, month, day, hours, minutes, secs, #day of the week, #day of the year, dst)
time_tuple = (2022, 4, 20, 4, 20, 0, 0, 0, 0)
time_tupstr = time.mktime(time_tuple)
print(time_tupstr)