Skip to content

Python print DateTime now | Example code

  • by

First, you have to get Today’s date and time then pass this value into a Python Print() function.

Example code print DateTime now in Python

Use the datetime class of the datetime module to get a DateTime in this task.

import datetime

now =


Python print DateTime now

More specific you can import the datetime object from the datetime module: Then remove the leading datetime. from all of the above.

from datetime import datetime

now =

Another example use time.strftime():

from time import gmtime, strftime

now = strftime("%Y-%m-%d %H:%M:%S", gmtime())

Output: 2021-07-28 08:42:08

Current date in different formats

from datetime import date

today =

d1 = today.strftime("%d/%m/%Y")

d2 = today.strftime("%B %d, %Y")

d3 = today.strftime("%m/%d/%y")

d4 = today.strftime("%b-%d-%Y")


Python print DateTime example code

Do comment if you have any doubts and suggestions on this python date-time topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.