Python gets the current time

藏色散人
Release: 2021-01-26 17:48:34
Original
17993 people have browsed it

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

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!

Related labels:
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