How to get the current date and time in Python

By: Editorial Staff | Last Updated: | In: Python Programming


Today we are going to share how to get the current date and time in Python. If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share how to get the current date and time in Python.

To increase your Python knowledge, practice all Python programs:

How to get the current date and time in Python

Copy the below python program and execute it with the help of python compiler.

Output

Current date and time using str method of datetime object:
2013-02-17 16:02:49.338517
Current date and time using instance attributes:
Current year: 2013
Current month: 2
Current day: 17
Current hour: 16
Current minute: 2
Current second: 49
Current microsecond: 338517
Current date and time using strftime:
2013-02-17 16:02

Share this post!


About: Editorial Staff

Editorial Staff at FreeWebMentor is a team of professional developers leads by Prem Tiwari