How to read the current time in python to the accuracy of seconds

Release: 2019-07-05 13:28:30
Original
3153 people have browsed it

How to read the current time in python to the accuracy of seconds

Import the time package and you can get the time through it

# -*- coding: UTF-8 -*-
import time

print(time.time())
# 输出:1562304217.5744529
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template