Hi everyone.
Welcome back to this tutorial.
In this tutorial we will code and learn the next class, which is the local time.
What I'm going to do is I'm going to create a class.
Paul local time example.
Local time example.
And then I'm going to make this class executable by adding public static void main method.
There you go.
We put this in presentation mode.
Now we will create the instance of local time, which is going to give you this machine's current time.
Local time.
I'm going to use a known method which we have seen in the previous tutorial and one of the previous
tutorial actually.
And then this is going to give you an instance of local time.
I'm going to create the local time and give it a name.
There you go.
Let's print this and check what is the time it is printing.
Local time.
And local time.
Let's run this and check the result.
We take a look at it.
This gives me the current machines time, which is 447 and 39 seconds, followed by the nanosecond precision.
Now let's take a look at what are the different options that are available in order to create a local
time instance.
Local time dot.
If I give Dot, these are the different options that I have.
I'm going to use the off version of it.
If you take a look at the off there are on minute and the other version is hour, minute and second,
and the other version is hour, minute, second and nanosecond precision.
And the other option is of nano of day of second of day.
Basically, we will we'll pass the nanosecond of the day and will pass the second of the day, which
will give you the appropriate local time.
As a result, we're going to explore these three options now because these are the most common commonly
used methods.
In order to create a local time instance, I'm going to pass the value as 2333.
Local time.
One.
Wanna copy this and put it here.
Let's print the local time one.
But on this program, this is going to give me the time instance which we used here of method.
So here, if we take a look at it, the time it printed is 23 and 33.
It did not print the second and nanosecond precision.
Now let's use the other version.
I'm going to give it a name and I'm going to pass the second.
And let's print this and check the result.
Going to be local time too.
And local time, too.
Let's run this and check what is the result.
If you take a look at it, the result is 23, 33, and the second position is also printed.
If you pass a nanosecond, it is going to give you the nanosecond position too.
I'm going to just put it here.
Local time three since it's a nanosecond, I'm going to give the values.
And then.
Put it here so that it will be clear for the whole and the whole screen.
It will fit the whole screen so that you will be able to view it then.
Right here.
Going to be local time three.
And then I'm going to run this.
Run this example.
There you go.
It gives you the nanosecond value of the time.
Now, these are the different options that we have in order to create the local time instance.
Now let's explore how can we get the hour, minute or second and many other parameters from the time
instance that we created here.
I'm going to use the local time as an example, and then I'm going to get the hour minute and the second
from it.
How do we get it?
I'm going to give a simple code comment here.
I'm going to be.
Getting the values.
From.
Local time instance.
So I'm going to use a local time.
I'm going to press dot and then see what are the methods that it supports.
It has a lot of methods, actually.
Now let's explore some of the methods to get the value from the local time instance.
As soon as I type in the get, it gives me the option of get second get or get long get minute and get
nano.
Let's say I want to I want to see what is the hour that this particular local time instance has.
So in that case we'll use the get method.
And then using this, we'll print the R of this local time instance.
Let's run this and check the result.
Take a look at it.
The r value it gave us for that's what.
That is what is the current local times current machines local time.
Now what we'll do we will see.
What is a minute?
Right.
I'm going to use the get minute field.
This is going to return me.
What is a minute of the local time instance?
Put it here.
Let's run this and check the result.
You run this.
It gave the result as 52, which is the machine's current minute.
No.
There are a lot of other methods, right?
Local time dot as you type in the get it is going to give you the option to get the second and it is
going to give you the option to get the Nano.
Now if you take a look at the get method, it accepts something called temporal field.
If you remember from the previous tutorial, we have seen one of the previous tutorial.
We have seen something called the Chrono Field where you can pass the field and then get the actual
value from that local time.
This is one other option basically, but it is going to give you the same result.
Actually.
Let's go ahead and explore this option to.
And then it's going to be Chrono Field.
Dot.
Let's say you want to clock out of the day, you cannot get a day of the month from a time instance.
It's going to give you that unsupported type exception.
So you should pass only the fields that are actually related to the time instance.
So I'm going to give the clock hour of the day.
Run this and check the result.
But here.
And then I'll copy this and put it inside.
There we go.
Run this.
It is going to give me the clock of the day from the actual local time instance.
And the value is for this result is similar to this result, but it is just another alternative to get
the R from the time instance.
Let's say you want to represent this whole time in seconds.
There is an handy option for that one too.
So the method that you have to call is to two seconds to second of day.
Basically, this is this will represent the current time in seconds.
Go ahead and run this example.
So two seconds is going to give you it's going to represent the time in seconds.
Run this.
And the value is 17,006 85.
Now we have seen the different we have seen different options of getting the values from the local time
instance.
Let's go ahead and check how do we modify the time once it is created?
Right now the time is four 5445.
Right.
How can we modify those times?
There are handy options or handy methods that are available in order to modify the value of the local
time.
Modify values of local time.
So if you remember from the local data instance, we are going to use similar kind of methods.
So I would highly recommend you guys to explore all the methods in this local time instance.
But I'm going to give you I'm going to give you the exposure to a few of the methods at this moment,
but please go ahead and run all the different methods that are available so that it will give you the
clarity of how which method to choose on what kind of use case that you are.
Using in your application.
So it's going to be local time, dot minus.
I'm going to subtract the hours by two.
So in that case I can give like minus hours and then pass the long value.
This is going to subtract the hours by two, and the result that it is going to print is something which
we are going to take a look at it now.
Going to be minus hours.
And I'm going to run this example.
Let's check the result and the time is subtracted.
So if you take a look at the current time, the current time is 456 and we subtracted the hours to 256
and again, local time is immutable.
It doesn't change the actual time of that instance.
Now let's say you want to see.
You want to perform the same minus using another alternative approach.
There is a handy way if we give minus.
There you go.
We're going to use this same approach which we have covered in the local date.
There is a similar option which is available in local time too.
So minus long amount to subtract.
And then the temporal unit.
Right.
Let's select that in here.
I want to subtract the hours by two hours and then the unit something which is called Chrono Unit Dot.
Let me put this below so that it will be visible to the.
Students Pronoun unit Dart ahs.
Okay, I'm going to copy this and put it here.
So we are subtracting the hours by two.
There you go.
Give the value as two 5738.
Again, it's all immutable.
It is not going to change the state of the local time instance now.
The Czechs were one of the wet method.
The white matter is something which we explored in the local date video.
Again, we have the similar kind of methods available in local time with and then I'm going to use the.
Local time instance with local time dot.
We take a look at it.
You can give if you want to make this time to be the midnight time, then you can just give this.
So what this is going to do, this is going to change the time to the midnight.
Night.
I'm going to run this example and this is going to give you the time set.
The time as midnight.
Let's say using the width itself.
You want to change the hour of the day?
How do we do it?
So then in that case, we are going to use the two parameter width option.
Let's type in the width and then check if we type in the width.
So there are.
So we just saw this option.
Now we are going to take a look at this option with which takes in the temporal field, followed by
that value.
So we should always, since we are working with the time instance, we should always pass the field
which is of type time, the Chrono Field dot or of day.
I'm going to use the hour of day.
And if you take a look at it, there are a lot of different options.
I would highly recommend you to go through each and every one of it and use the fields that map to the
local time instance, not the date instance.
If we give date, you're going to get something like unsupported type.
So I'm going to use the clock hour or the clock or the hour of day, right?
Hour of day.
And I'm going to set the value as 22.
Gonna run this example and check the result.
We check the result.
It is going to change a time to 22 hours.
So if you take a look at it, it change a time from 459 to 2259.
Now if you want to add some minutes, how do we do it?
Right?
Now, copy this.
Local time, Dot.
Diamond.
Plus, it gives you the all of the different options plus minutes.
And then I'm going to give the value as to.
I'm adding the minutes by to let's go ahead and check the result.
Otherwise I'm going to add the minutes as 30 so that it will be a big difference so that you can easily
compare with the current time.
So if you take a look at the result, the current time is five and the plus minutes, which change at
minutes from zero 0 to 513.
So this is how you add minutes to the local time so you can add our time, our second nanosecond and
all those things.
Now what I'm going to do, I'm going to use the with our method.
The change are of the time.
How do we do it?
The local time dart with R, so it has those methods.
You can directly parse the value and change the hour, minute, nanosecond and second.
So this is again an alternative, but ultimately it is going to give you the same result with R, I'm
going to change the R to ten.
But let's run this example and check the result.
We take a look at it.
It changes a time from zero 5 to 10.
So there are a lot of additional methods.
What are we covered in?
Local date also is supported in local time.
Basically the equal is after, is before and is leap year and all those things.
But leap year doesn't apply here because that's related to the date kind of functionality.
So this is all about the local time instance.
With this, we came to the end of this tutorial.
Thank you for watching.