How to get the current time in Python

0 votes

What is the module/method used to get the current time?

Jul 20, 2018 in Python by eatcodesleeprepeat
• 4,710 points
1,667 views

3 answers to this question.

0 votes

You can use time.strftime():

>>> from time import gmtime, strftime

>>> strftime("%Y-%m-%d %H:%M:%S", gmtime())

'2009-01-05 22:14:39'

answered Jul 20, 2018 by Priyaj
• 58,090 points
0 votes
print(datetime.datetime.today())
answered Feb 14, 2019 by Shashank
• 1,370 points
0 votes

FOLLOWING WAY TO FIND CURRENT TIME IN PYTHON 

By default now() function returns output in YYYY-MM-DD HH:MM:SS:MS format. Use below sample script to get current date and time in Python script concept.

program

import datetime
currentDT = datetime.datetime.now()
print (str(currentDT))

output

2019-04-08 O3:11:04.159338

answered Apr 8, 2019 by rajesh
• 1,270 points

Related Questions In Python

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
512 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,910 points
419 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
496 views
0 votes
2 answers

how to print the current time using python?

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

answered Feb 14, 2019 in Python by Shashank
• 1,370 points
679 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,007 views
0 votes
1 answer
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29, 2019 in Python by rajesh
• 1,270 points
1,532 views
0 votes
1 answer

How do you get the logical xor of two variables in Python?

What i found is that you can use ...READ MORE

answered Aug 10, 2018 in Python by Priyaj
• 58,090 points
11,300 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