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,890 points
59 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,210 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 in Python by rajesh
• 1,210 points
92 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,810 points
56 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 21 in Python by Taj
• 1,040 points
54 views
0 votes
2 answers

how to print the current time using python?

print(datetime.datetime.today()) READ MORE

answered Feb 14 in Python by Shashank
• 1,350 points
63 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 417 views
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,210 points
85 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,210 points
61 views