time.time()
will give you the number of seconds since 1.1.1970 in UTC.
So begin
is a huge number and count
will also be a huge number + about 1. Subtracting those will give about 1.
If you pass this to time.time()
you'll get 1.1.1970 plus 1 second. Converting to local time (time.localtime()
) will give you whatever timezone offset you are. Obviously +9 hours.
What you probably wanted is time.gmtime()
and output in 24 hour format. This will work...
import time
start = input("Enter를 누르면 타이머를 시작합니다.")
begin = time.time()
while True:
time.sleep(1)
count = time.time()
result = time.gmtime(count - begin)
print(count - begin)
print(time.strftime('%H:%M:%S', result))
but it is semantically incorrect. If you subtract 2 dates, the result is a timespan, not a date. What is the difference?
If someone asks, how old you are, you have a look at the current year and you subtract the year of your birth. Then you say "I'm 25 years old". You don't add 1.1.1970 and say "I'm 1995 years old".
So the following is semantically much better:
import time
from datetime import timedelta
start = input("Enter를 누르면 타이머를 시작합니다.")
begin = time.time()
while True:
time.sleep(1)
count = time.time()
timespan = timedelta(seconds=count - begin)
print(timespan)