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
67 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
• 56,580 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,810 points
47 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
42 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
52 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
95 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 272 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
89 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,580 points
646 views