In php
echo time();
and you get some 10 digit time stamp.
in python..
import time
>>> print time.time()
1374872354.62
where is the PHP's time()
equivalence in Python ?
In php
echo time();
and you get some 10 digit time stamp.
in python..
import time
>>> print time.time()
1374872354.62
where is the PHP's time()
equivalence in Python ?
Python uses a float type so that it can represent fractional time. Just cast away that part:
>>> import time
>>> int(time.time())
1374872983
Ok so python's time() comes from the time
module :)
which may or may not give the best time for your system:
time()
"Return the time in seconds since the epoch as a floating point number. Note that even though the time is always returned as a floating point number, not all systems provide time with a better precision than 1 second. While this function normally returns non-decreasing values, it can return a lower value than a previous call if the system clock has been set back between the two calls." - Python Time doc
sometimes clock() may work better:
"On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the same name, but in any case, this is the function to use for benchmarking Python or timing algorithms. - Python Time doc "
depending on your use you should choose one of these: for a discussion see here: Python - time.clock() vs. time.time() - accuracy?
PHP time according to the docs does the following:
"Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). " -- PHP docs
So no matter which one you choose; you're most likely to get the same if not better resolution than PHP's time :)
If you want to time a function though, you should try the timeit
module which automatically chooses from either clock
or time
depending on the OS granularity