Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)
Which method is used to get the current time using python?

1 Answer

0 votes
by (26.4k points)

Try:

>>> import datetime

>>> datetime.datetime.now()

datetime.datetime(2009, 1, 6, 15, 8, 24, 78915)

>>> print(datetime.datetime.now())

2009-01-06 15:08:24.789150

then:

>>> datetime.datetime.now().time()

datetime.time(15, 8, 24, 78915)

>>> print(datetime.datetime.now().time())

15:08:24.789150

You can also directly import datetime object from datetime module:

>>> from datetime import datetime

Are you interested to learn python in detail? Come and Join python certification course.

Watch this video tutorial on how to become a professional in python.

Related questions

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...