Time delta plus a time Delta is a duration expressing the difference between due date or daytime objects
so a time Delta represents the time difference between two events and it is normally used to add or
remove a certain duration of time from a date or a daytime object.
These are the following attributes defined in the time Delta class days.
Second microseconds milliseconds minute.
I was and weeks in order to create a time Delta object.
We simply need to parse a specified duration to the class constructor and by default a single integer
pass to the class constructor the present number of days so time.
Delta of 10 gives us an object that represents 10 days.
Let us now create a time Delta object indeed JUPITER KNOWN book Let does not create a time Delta object.
Delta 1 we will pass these values to the constructor.
Time Delta constructor so we will begin with the attribute weeks and then days minutes was microseconds
so these are the different attributes that we are going to pass to the class constructor execute this
in and then display the object Delta 1.
The first attribute in this instance that is Delta 1 represents the number of days so Delta 1 dog days
is going to give me the first attribute to value the second attribute for this particular instance is
second.
So Delta 1 dot second represents the value of the attribute second for this particular instance.
Delta 1 and then the third attribute is microseconds which is 23 now when creating these object Delta
1.
We have passed the argument weeks days minutes hours and microseconds now when we display the object
Delta 1.
It only shows the attributes for days seconds and then microseconds.
This is because internally the attribute days seconds and microseconds are stored and all other arguments
like weeks milliseconds.
I was at all converted to these units that these days seconds and microseconds.
So in our example when creating the object Delta 1 these are the values we have passed to the class
constructor.
Now when we display the object Delta 1 This is what is shown in the output.
This is because internally only the attribute days seconds and microseconds are stored and all other
attributes say for example weeks is converted two days so one week.
In our example is converted to 7 days and then minutes is converted to seconds with the 60 seconds the
attribute hours is converted to seconds.
So there are 60 into 60 seconds in an hour and so on the attribute millisecond is converted two thousand
microseconds minute is converted to 60 seconds an hour is converted to 3600 seconds and displayed in
the output accordingly.
So if you create a time Delta object but arbitrary combination of time durations represented with days
weeks minutes hours etc. and that combination will be simplified to represent the time Delta object
in days seconds and microseconds all the different parameters defined in the time Delta class add optional.
So if you do not pass any value to a parameter that means a default value of zero is assumed and due
value to these arguments can be integers floating by numbers and can also be a positive or a negative
number.
We will now see these valid range of values for a time Delta object by calling the attribute men.
This is the minimum value of a time Delta object.
Next we will call the attribute Max and these are the maximum representing all values for a time Delta
object for days and then seconds and microseconds coming to this attribute men.
If you want to create a time Delta object using the least possible value it is going to be this value
and this negative value represents days.
Keep in mind that the time Delta object can only have a negative value in these days field and no other
attribute other than the days attribute can be represented as a negative number.
No let us try creating a time Delta object by giving a negative value for the second field but let's
call this object Delta 2 and to the class constructor time Delta.
We are going to parse two arguments days is 1 and then seconds is minus 4000.
Let's execute this line and then display the object Delta 2 the time Delta object is represented like
this in days and in seconds.
So how was this conversion done.
Let's talk about that so we have just discussed that no other attribute other than the D attribute can
be represented as a negative number.
But when creating the object a time Delta object we have passed a negative value to the attribute now
in the background the value of the days attribute is converted into seconds so that add 24 in to 60
into 60 seconds in a day.
Which is eighty six thousand four hundred and now this value is added to the second value in this attribute
so minus four thousand.
This is going to give eighty two thousand four hundred
so the time Delta object Delta 2 will now be represented like this.
Days is zero and then second is this value.
We will now see some of the methods that are defined in the time Delta class.
Let's call the desired function and parse time Delta to this function.
We will first begin with the the method.
Total seconds.
Now let's call the method.
Total seconds on this object.
This method total second gives total number of seconds represented by this object.
Let's call this method again on another object.
Delta 1.
Total number of seconds for this particular instance.
Delta 1.
Next we will call the built in function.
A B is and then pass the object Delta 1 and the ABC s function it returns distorted.
Duration of the particular instance which is represented as a positive number say for example we will
pass another time Delta object which has the days as a negative value minus 1 and then execute this
line.
The built in function a b is has returned an absolute value for the attribute D which is a positive
number.
The time Delta object supports various mathematical operations such as addition subtraction multiplication
division modulo etc. Using basic operators.
So let's discuss about some of these mathematical operations beginning with the method double underscore
month.
So let's call this method on the object Delta 1.
The method w underscored model allows for the multiplication of time Delta object by numbers execute
this line.
Each of the attributes defined in this time Delta object Delta 1 has been multiplied with this integer
to next we will call the float division method the flawed division method allows dividing one time Delta
object by another time Delta or by an integer flawed or a decimal value.
So in this we are going to divide a time Delta object Delta 1 by the integer to let execute this
and the flawed division compute the questioned and they demanded.
The remainder is thrown away and this is decommissioned a time Delta object.
Next we will talk about the string method these string method returns a string representation of our
time Delta object.
So let's parse the object Delta 1 to the method string
and this returns a string in the form of days I was minutes and seconds if I did time object is subtracted
from another daytime object the value that is added don't is that the time.
Time delta so let's see this.
Let's subtract D2 2 from D2 1 which are 2 daytime objects let's execute this line and the result is
a time Delta object.
Which has these two attributes one is the days and the other.
Second
so if you subtract a daytime object from another daytime object the value that is red done is of the
type time Delta.
Now if you add a daytime object to a time Delta which is say a specified duration this is going to result
in a daytime object.
And if you add to time Delta objects say Delta 1 and Delta 2 this is going to determine what time Delta
object.
The difference between these two daytime objects as Delta 3 lit displayed this object.
Delta 3.
So this is a time Delta object.
Now as discussed let's add the daytime object d d to do a time Delta object.
Delta 3.
Let's execute this line.
And this addition operation has returned a daytime object which has the same values as the daytime object
D.T. 1 so subtracting date produces a time Delta object and a time Delta object can be added or subtracted
from a date to produce another date.
And this brings us to the end of this tutorial on time Delta.
Class.