How to get current time in Python?

0 votes
What method is used to get the cuurent time as output?
Jun 21 in Python by Shabnam
• 920 points
26 views

1 answer to this question.

0 votes

Hi,

You can use Datetime class.

Input:

import datetime
datetime.datetime.now()

Output:

datetime.datetime(2019, 6, 21, 13, 55, 50, 438476)

Input:

print(datetime.datetime.now())

Output:

2019-06-21 13:56:25.974482

And now for just time:

Input:

datetime.datetime.now().time()

Output:

datetime.time(14, 2, 0, 844387)

Input:

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

Output:

14:02:15.714107






answered Jun 21 by Taj
• 1,040 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
56 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
39 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
38 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by ariaholic
• 7,340 points
74 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 175 views
+4 votes
6 answers
0 votes
1 answer

How to put time delay in Python?

You can use sleep() method to sleep ...READ MORE

answered May 28 in Python by Taj
• 1,040 points
22 views
+1 vote
1 answer

How can I reverse list in Python?

Reversing a list is a commonly used ...READ MORE

answered May 13 in Python by Taj
• 1,040 points
36 views