Home > Article > Backend Development > Python gets the current time
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:
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:
#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!