The float timestamp used in Python seems to be problematic. First, it will lose its precision as time goes on, and second, the timestamp is not usable, for example, storing in a database big integer field.
Is there a predefined way to use integer time? I know the seconds integer can be found using
timestamp_int = int(datetime.datetime.now().timestamp())
but wouldn't it have been better if there was a way to do like:
datetime.datetime.now().itimestamp()
Is there an official way other than doing a hack around? What is the point of using float when everyone else is using an integer instead?
You could use time.time_ns()
instead. It returns the number of nanoseconds from the epoc as an int
.