What is the module/method used to get the current time?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Do
t
- float number, good for time interval measurement.There is some difference for Unix and Windows platforms.
If you need current time as a
time
object:Similar to Harley's answer, but use the
str()
function for a quick-n-dirty, slightly more human readable format:Simple and easy:
Using the
datetime
module,Output:
OR
Using
time
,Output:
Use:
And just the time:
See the documentation for more information.
To save typing, you can import the
datetime
object from thedatetime
module:Then remove the leading
datetime.
from all of the above.You can use the
time
module.The use of the capital
Y
gives the full year, and usingy
would give06/02/15
.You could also use to give a more lengthy time.