What is the date and time ?

Let us learn to print the current date and time using Python.

We will be using the datetime module for this purpose.

screenshot-65.png

First we import date from datetime module. According to the python documentation, the datetime module supplies classes for manipulating dates and times in both simple and complex ways. We assign today’s date to the variable called now and print it. We get to see the date as a tuple. Next we use strftime to convert it to a string and print it in a sentence. 

%b gives the abbreviated month name.

%Y gives the year including the century.

%A gives the name of the week day.

%d gives the day of the month(1 to 31).

%B gives the name of the month.

screenshot-66.png

Similarly in the above way we get the time also and print it using strftime.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: