Read Python Interview Questions and Answers for Beginners and Experienced

Python datetime example

In this Python tutorial, we will study about another Python example i.e Python datetime example.

Let’s see Python datetime examples. As datetime deals with date and time in Python.

Python datetime example

Get Current date and time

#Python datetime example

import datetime

x = datetime.datetime.now()
print(x)
2019-04-13 10:53:10.704525

 

  • To use datetime in Python, we have to import datetime module of Python.
  • using now() function of datetime we can get the current datetime in Python