python reads out the code of the current time precision to seconds
- 2021-07-09 08:52:51
- OfStack
Import the package time and you can get the yes time through it
# -*- coding: UTF-8 -*-
import time
print(time.time())
# Output: 1562304217.5744529
After executing the above code, we found that we got a timestamp, which is based on the second data from 1970 to the present
However, many people need not a timestamp, but something that everyone can understand (year, month, day, hours and seconds)
So we need to calculate this timestamp, 1 minute is 60 seconds, so we need to calculate minutes, which can be solved by modular operation. But someone has already done this calculation for us, so we just need to use (code) like this:
# -*- coding: UTF-8 -*-
import time
print(" Current time: ",time.strftime('%Y.%m.%d %H:%M:%S ',time.localtime(time.time())))
# Output: Current time: 2019.07.05 13:23:04
Content extension:
Python3 Get the current time (to seconds)
Output in format:
print(" Current time: ",time.strftime('%Y.%m.%d %H:%M:%S ',time.localtime(time.time())))