Get the Current time in Python

0 votes
I want to know the module or method to get the current time in python. how do we do that?
Oct 3, 2018 in Python by ana1504.k
• 7,910 points
702 views

1 answer to this question.

0 votes

To get the current date and time in python, use the following code:

>>> import datetime
>>> datetime.datetime.now()
datetime(2018, 1, 6, 15, 8, 24, 78915)

>>> print(datetime.datetime.now())
2018-10-03 09:17:13.812189

And to get only the time, use the following code:

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

>>> print(datetime.datetime.time(datetime.datetime.now()))
09:17:51.914526
answered Oct 3, 2018 by SDeb
• 13,300 points

Related Questions In Python

0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

answered Apr 8, 2019 in Python by rajesh
• 1,270 points
2,117 views
0 votes
1 answer

How to get the current time in Python

>>> import datetime >>> datetime.datetime.now() datetime(2018, 25, ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,830 points
817 views
0 votes
1 answer

How to get the current time in Python?

Use: >>> import datetime >>> datetime.datetime.now() datetime.datetime(2009, 1, 6, 15, ...READ MORE

answered Nov 20, 2020 in Python by Gitika
• 65,770 points
685 views
0 votes
1 answer

How to get current time in Python?

Hi, You can use Datetime class. Input: import datetime datetime.datetime.now() Output: datetime.datetime(2019, 6, ...READ MORE

answered Jun 22, 2019 in Python by Taj
• 1,080 points
766 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,488 views
0 votes
1 answer
0 votes
1 answer

Is arr.__len__() the preferred way to get the length of an array in Python?

my_list = [1,2,3,4,5,6,7] len(my_list) # 7 The same works for ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 13,300 points
981 views
0 votes
1 answer

What are the ternary conditional operator in Python?

The Ternary Conditional operator was added in ...READ MORE

answered Sep 19, 2018 in Python by SDeb
• 13,300 points
762 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP