Getting a localized timestamp is really simple with Python a simple
time.time() does the tricks. But what about getting an UTC timestamp
regardless of the current system time?
To get this information many techniques exists, most common is to subtract the timestamp starts from the current time:
This technique work greate but it requires setting by hand the timestamp start time. To avoid this the calendar module from the standard lib.can be used:
As the two techniques returns the same results, let’s benchmark it:
We can see that the calendar technique is nearly two time longer than the subtract one but as the execution time is close to nothing (few micro-seconds) the choice stays open depending of your usage and maybe also the readability of your code.