Answer
Code:
import time
# Prompt the user to enter the time zone offset to GMT
timeZoneOffset = eval(input("Enter the time zone offset to GMT: "))
current Time $=$ time.time ()$\#$ Get current time
# Get total, current seconds since midnight, Jan 1, 1970
totalSeconds $=$ int(currentTime)
currentSecond= totalSeconds\% 60
# Get the total and current minutes
totalMinutes $=$ totalSeconds $/ / 60$
currentMinute $=$ totalMinutes $\% 60$
# Get the total hours
totalHours $=$ totalMinutes $/ / 60$
# Compute the current hour, include GMT offset
currentHour= (totalHours + timeZoneOffset) \% 24
# Display time with GMT offset
print("Current time is", currentHour, ":", currentMinute
,":", currentSecond)
Work Step by Step
Step 1 of 3:
Program Plan:
- Prompt the user to enter the time zone offset to GMT.
- Get the current, and total seconds, current, total minutes and total hours as per earlier.
- Get the current minute in this hour, include the GMT offset.
- Display the current time as earlier.
Step 2 of 3:
Code:
import time
# Prompt the user to enter the time zone offset to GMT
timeZoneOffset = eval(input("Enter the time zone offset to GMT: "))
current Time $=$ time.time ()$\#$ Get current time
# Get total, current seconds since midnight, Jan 1, 1970
totalSeconds $=$ int(currentTime)
currentSecond= totalSeconds\% 60
# Get the total and current minutes
totalMinutes $=$ totalSeconds $/ / 60$
currentMinute $=$ totalMinutes $\% 60$
# Get the total hours
totalHours $=$ totalMinutes $/ / 60$
# Compute the current hour, include GMT offset
currentHour= (totalHours + timeZoneOffset) \% 24
# Display time with GMT offset
print("Current time is", currentHour, ":", currentMinute
,":", currentSecond)
Step 3 of 3:
Sample Output:
Enter the time zone offset to GMT: $-5$
Current time is $1: 51: 50$