Categories
Python Answers

How to get the current time in Python?

Spread the love

Sometimes, we want to get the current time in Python.

In this article, we’ll look at how to get the current time in Python.

How to get the current time in Python?

To get the current time in Python, we can use the datetime.datetime.now method.

For instance, we write:

import datetime

t = datetime.datetime.now().time()
print(t)

We call datetime.datetime.now to get the current date and time.

And then we call time to return the current time.

Conclusion

To get the current time in Python, we can use the datetime.datetime.now method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *