Python Date, Calendar, time
In program many time we need date and time, here we will learn some usable function related to time.
The Python datetime module supplies classes for manipulating dates and times in both simple and complex ways.
While date and time arithmetic is supported,
Python datetime module
Here we'll find out today date by using Python datetime
module. In order to print today's day, datetime.time.today()
will be used as shown in figure below.
The out-put is easy to see but very difficult to use in program. If you want to use the date string, you have to use isoformat()
we want to print today's date, use datetime.date.today().isoformat()
As show in figure below.
Datetime in real life
Now we'll print the current time using datetime.datetime.now().isoformat()
Datetime now in real life
Consider a situation where you want to calculate the processing time of running program.
as shown in figure given below.
Showing time difference
Time difference is about 52 seconds.
Python Calendar module
Now we'll use calendar
module to print the calendar of particular month. In order to print particular month,
would be used as shown in figure below.
Output is very beautiful, you make calendar of any month.
Python time module
The Python time
module gives you very interesting things.
To produce delay in the the program, use time.sleep(seconds)
gives float time value.
gives the human readable time.
If you want to print to time after certain seconds, use time.ctime((time.time() + 15)).
The below example shows all above things.