In this answer, you will learn to get today’s date and current date and time in Python. We will also format the date and time in different formats using strftime()
method.
1 2 3 4 5 6 | >>> import datetime >>> datetime.datetime.now() datetime.datetime(2009, 1, 6, 15, 8, 24, 78915) >>> print(datetime.datetime.now()) 2009-01-06 15:08:24.789150 |
And just the time:
1 2 3 4 5 | >>> datetime.datetime.now().time() datetime.time(15, 8, 24, 78915) >>> print(datetime.datetime.now().time()) 15:08:24.789150 |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.