Hello welcome to this tutorial on the daytime module
the daytime module provides classes and functions to work with times date and time maintenance and the
daytime module as part of the python's Standard Library which means we do not have to install it separately.
We can simply import as he's into our programs and these are some of the classes that we are going to
discuss in this tutorial time.
Date date time and time.
Delta Python provides a variety of time and date processing methods.
In the daytime module and these are the classes that are defined in the daytime module time date date
time and time Delta and each of these classes define a number of methods or functions that can be used
to manipulate date time and time intervenes.
Say for example the time class defines the method IE is so format and and the method as these are if
time both of these methods can be used to give a string representation of the time instance the object
that is created using daytime class we will see various methods when we have a detailed discussion on
each of these classes before discussing about the classes defined in the daytime module.
We need to understand some basic terms beginning with timestamp a timestamp is the current time of an
event that is recorded by a computer.
Say for example of a computer files contain timestamps that tell us when the file was last created or
modified timestamp is a sequence of characters or encoded information identifying when a certain event
has occurred and the timestamp usually gives the date and time of the day when the event has occurred.
Sometimes accurate to a small fraction of a second.
And these are some of the different format in which timestamps can be represented next unix time unix
time is also known as politics time or Unix epoch.
Time is a system for describing a point in time and also the UNIX timestamp is the number of seconds
from some arbitrary point in the past.
And for Unix systems it is the first of January 1970 UDC epoch is nothing but an instant of time or
a date selected as a point of reference for Unix systems.
This is the date which has been chosen as the epoch time which is the midnight of the first of January
nineteen seventy and what is the Unix epoch time used for this timestamp or the Unix epoch.
Time is used by the computer to tell the time and the date timestamp for the Unix epoch time is marked
as zero and today's date is is July 4th 2000 19 and a need time since this date is calculated based
on the number of seconds elapsed.
So in simple words the time stamp of the Fourth of July 2019 will be the difference in seconds between
this date and the first of January nineteen seventy.
So basically the computer tells the time by keeping a count of each passing second since the first of
January nineteen seventy and this is stored as an integer.
So the e-book reference date is a point on the timeline from which we count time and moments before
this time.
That is the epoch time are counted with a negative number.
And moments after are counted with a positive number.
Also there are many e-books in use today.
So for example for the Windows systems the e-book time is the first of January.
Sixteen hundred and four Mac systems.
It is the first of January nineteen hundred and for the next term that we're going to talk about of
the ISO 8 6 0 1 format the ISO 8 6 0 1 standardize is the representation of date and times and these
standard representations are used to construct timestamp values and also this standard the ISO 8 6 0
1 provide an extensive set of practically well designed for months for expressing the date and time
values as text and these four months are easy to pass by machines as well as easy to read by humans
across cultures and these are some of the ISO 8 6 0 1 date and time formats the next term is coordinated
Universal Time UTC UTC is the time standard commonly used across the world and the world's timing centres
have agreed to keep their timescales closely synchronized or coordinated and hence the name coordinated
Universal Time and UTC or the coordinated Universal Time is a standard and not a time zone and it is
the base point for all other time zones in the world and if you want to determine the time zone of a
particular region it can be determined by its different to the UDC and UTC is represented like this
the Unix or deposits timestamps that we discussed before are always based on UTC we will now discuss
the various classes defined in the daytime module beginning with the time plus the time values are represented
with the timed class and the timed class provide access to where it is time related methods or functions
and it has the R word minute second microsecond as D attributes in order to create an instance or an
object of the time plus we need to access the time class defined in the daytime module using the dot
operator so the time class can be accessed using did DOD operate like this.
Date time.
The module name and the last name is time separated by the dot operator and the time class has the attribute
of it minute seconds and then microseconds and this is going to create a time object and the arguments
to initialize a time instance are an object add option in if the arguments are not provided a default
of 0 is assumed in order to create an instance of an object of the time.
Class B would have to first import the daytime module so let's import the daytime module using the import
statement now we can access the different classes using the dot operator.
So let us suppose to create an instance of the time class let's call this instance D one daytime dot
time and let's pass the arguments for the other word and then minutes seconds and then execute the same
lit display.
The object to 1 T 1 is an object of the date time dot time class and here are these values for each
of the attributes.
We can also create new time objects by using the replace method on an existing time object.
So how does this work.
So let's call our new instance as D2 and this is being created from the old instance T1.
We need to call the replace method on the old instance in order to create new instance of the new object
and to this replace method.
We need to parse new while used for the R word minute and second attribute.
If you do not pass any values to any of the attribute that remains the attribute value remains unchanged.
Say for example I only want to change the attribute of what the value is going to be twenty three the
arguments minute and second remain unchanged.
So let's display the objects too.
So as you can see new value for the I would attribute 23 has been assigned to this time object T to
and let us also display the object T 1 and the values for this object are not changed.
Let us now see the valid range of values for a time object using the minimum and maximum.
Class attributes.
So in order to call these attributes let's use the dot operator daytime dot time dot Min
so these are the minimum.
Let us now see the maximum values that can be assigned to the time object and these are the maximum
values that can be assigned to a time object and then you can display each of the attributes the individual
attributes like upward minute second on time object by using the dot operator.
So this is how you display the individual attributes if you want to represent your day time or time
object in a string format you can call the method ISO format on the daytime or time object so let's
call the yes so format method on the object.
D 1 and this is how the ISO 8 6 0 1 represents the time object in the form of a string.
If you want to know the various methods or attribute that that are defined on a date time or time object
you can use the desired function and pass day time dot time to the desired function and then execute.
And here you have the various functions and attributes that are defined in the time class.
We can also compare time values using these standard operators in order to determine which is earlier
odd later so let's compare these two objects D1 and D2 using the greater than operator so t1 is less
than T2 and this is returned to let us now discuss another method defined in a time class which is s.t.
out of time method which stands for string format time method.
This method allows us to create a string that represents a time in a more human readable format.
So let us say we want to create a string and output string in this format from the daytime dot time
object.
D 1 and we need to parse a string.
To the method is t r f time say for example this string in school if we need to parse a string pattern
to this method s.t. out of time and this string pattern explained how we need to format our time object
so let's first create a string pattern.
So here I have created a string pattern which explains the method SDR a time how the output string should
be represented in string format.
Now we have called the SDR of time on the object T 1 and have passed this string pattern variable.
Now when the estimate of time method read the string pattern or the format it encounters this operator
modulo and when this method encounters the modulo operator it knows that it needs to replace the modulo
operator along with the letter following the operator with a certain code.
Odd also known as a format code and here is a list of format quotes which are used by SDR of time method
to return a String based on these codes.
Say for example we want to print the value of the R word attribute from the daytime die time object
in the output string.
So in that case we need to use the modulo hedge format called the modulo hedge.
Court gives these others as a zero padded decimal number like this and then in order to display the
minute in the output string we use the modulo M chord and this gives the minute as a zero by the decimal
number and then modulo s in order to display these seconds as a zero padded decimal number.
So let's see an example in the Jupiter notebook which uses these format codes to convert daytime or
time object into a string.
No let's call the SD ata time method on the object T 1 in order to display this object in a human readable
format to the SD out of time method.
We need to pass a format or a string pattern.
So in this pattern we are going to separate the different attribute the hour minute and seconds with
a colon.
So in order to first display the others we are going to use the DB format called modulo H which is going
to display the others in the object and then this is separated with a colon and then we're going to
display the minute using the format called modulo M and then this is separated by a colon.
And finally we're going to display the second which is represented by modulo s.
Now let's execute this line.
So now we have the obvious minutes and second displayed in the form of a string and calling the SD out
of time method on the daytime long time object.
Create a new string.
And it does not affect the object.
And here we have these object daytime dot time.