-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_module.py
More file actions
33 lines (23 loc) · 849 Bytes
/
time_module.py
File metadata and controls
33 lines (23 loc) · 849 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
25
26
27
28
29
30
31
32
33
Q) Compute the number of days since January 1, 1970 and the current time of day in hours, minutes, and seconds.
Solution:
# Solution goes here
#compute number of days since january 1, 1970
#current time of day in hrs, min, sec
total_seconds = time.time()
#get current time in seconds since jan 1, 1970
seconds_per_minute = 60
seconds_per_hour = 60*60
seconds_per_day = 24*3600
#number of full days since epoch
days = total_seconds // seconds_per_day
#remaining seconds after removing days
remaining = total_seconds % seconds_per_day
#hours
hours = remaining // seconds_per_hour
remaining = remaining % seconds_per_hour
#minutes
minutes = remaining // seconds_per_minute
#seconds
seconds = remaining % seconds_per_minute
print("Days since Jan 1, 1970:", days)
print("Current time:", hours, "hours", minutes, "minutes", seconds, "seconds")