Home>Article>Backend Development> Python gets the current time

Python gets the current time

藏色散人
藏色散人 Original
2021-01-22 15:33:02 17912browse

How to get the current time in python: first download and install python; then create a py file and enter the content "datetime.datetime.now..."; then open the cmd window and enter "python py file name" command; finally click Enter to get the current time.

The operating environment of this tutorial: Acer S40-51 computer, Windows10 Home Chinese version system, python3.8.6 version

Recommendation: "python video tutorial"

python gets the current time

First download and install python;

Download address:https://www.python.org/downloads /windows/

Open the official website download link as shown below, click:

Python gets the current time

Note: Choose the version that suits your computer

Then create a py file in the folder phpcn01. I named it datetime_1 here. The code content is as follows:

import datetime x = datetime.datetime.now() print(x)

Then open the cmd window and enter "python py file name". My file name is datetime_1, as follows As shown in the picture:

Python gets the current time

#Finally click Enter to get the current time!

Note: You must switch to the path of the py file to run successfully~ You can switch through the cd command~

The above is the detailed content of Python gets the current time. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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