I am trying to create a TOTP generator. This needs a 'counter value' which uses the following formula: Calculating counter value
CT Count of the number of durations TX between T0 and T
T Current time or Unix time
T0 some epoch (eg. Unix epoch is 0)
TX length of one time duration (eg 30 seconds)
My code is:
from datetime import datetime
import math
window = 60
epoch = datetime.utcfromtimestamp(0)
timenow = datetime.now()
timekey = math.floor((timenow - epoch).total_seconds() / window)
print(timekey)
However, this results in slightly different values when running on my local linux machine, vs tio.run (not sure what OS), I don't have a windows or macOS machine handy to test.
My machine: 26654068
TIO: 26654008
Why is my code not producing the same value? Do one of the datetime functions not do what I was expecting?