To print timestamp in Python is very simple, all you have to do is, import the time library and call the time() function to get the timestamp.
But the problem most of us facing is where it will return a float result like this:
1 2 3 4 5 |
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import time >>> print (time.time()) 1428684549.944626 |
To get the actual Unix timestamp, just type cast the float value into int()
the result is,
1 2 3 4 5 6 |
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import time >>> print (int(time.time())) 1428684706 >>> |