Import the time package and you can get the time through it
# -*- coding: UTF-8 -*- import time print(time.time()) # 输出:1562304217.5744529
After executing the above code, we found that what we got was a timestamp. This timestamp is based on Second data from 1970 to the present
But many people don’t need a timestamp, but something that everyone can understand (year, month, day, hour, minute and second)
So we need When calculating this timestamp, one minute is 60 seconds, so we have to calculate the minutes. These can be solved through modular arithmetic. But someone has already done this calculation for us, we only need to use it like this (the above code):
# -*- coding: UTF-8 -*- import time print("当前时间: ",time.strftime('%Y.%m.%d %H:%M:%S ',time.localtime(time.time()))) # 输出:当前时间: 2019.07.05 13:23:04
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to read the current time in python to the accuracy of seconds. For more information, please follow other related articles on the PHP Chinese website!