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,670 points
34 views

3 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 56,120 points
0 votes
print(datetime.datetime.today())
answered Feb 14 by Shashank
• 1,350 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 by rajesh
• 1,210 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,570 points
20 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
19 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,320 points
47 views
0 votes
1 answer

Get the Current time in Python

To get the current date and time ...READ MORE

answered Oct 3, 2018 in Python by SDeb
• 9,460 points
22 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
19 views
–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 in Python by rajesh
• 1,210 points
40 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
• 56,120 points
101 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.