WEBVTT

00:00.960 --> 00:01.560
Hi everyone.

00:01.560 --> 00:02.790
Welcome back to this tutorial.

00:02.790 --> 00:08.010
In this tutorial we will code and learn the next class, which is the local time.

00:08.370 --> 00:11.250
What I'm going to do is I'm going to create a class.

00:12.350 --> 00:14.330
Paul local time example.

00:16.110 --> 00:18.900
Local time example.

00:19.200 --> 00:25.170
And then I'm going to make this class executable by adding public static void main method.

00:25.830 --> 00:26.580
There you go.

00:27.360 --> 00:28.980
We put this in presentation mode.

00:29.670 --> 00:38.190
Now we will create the instance of local time, which is going to give you this machine's current time.

00:39.200 --> 00:41.060
Local time.

00:42.600 --> 00:47.280
I'm going to use a known method which we have seen in the previous tutorial and one of the previous

00:47.280 --> 00:48.360
tutorial actually.

00:48.990 --> 00:53.670
And then this is going to give you an instance of local time.

00:53.850 --> 00:58.680
I'm going to create the local time and give it a name.

01:00.170 --> 01:00.680
There you go.

01:01.130 --> 01:03.890
Let's print this and check what is the time it is printing.

01:07.140 --> 01:07.980
Local time.

01:10.410 --> 01:11.410
And local time.

01:11.430 --> 01:13.050
Let's run this and check the result.

01:16.270 --> 01:17.180
We take a look at it.

01:17.200 --> 01:25.480
This gives me the current machines time, which is 447 and 39 seconds, followed by the nanosecond precision.

01:25.960 --> 01:31.750
Now let's take a look at what are the different options that are available in order to create a local

01:31.750 --> 01:32.920
time instance.

01:34.670 --> 01:36.590
Local time dot.

01:36.620 --> 01:40.230
If I give Dot, these are the different options that I have.

01:40.250 --> 01:44.330
I'm going to use the off version of it.

01:44.510 --> 01:51.980
If you take a look at the off there are on minute and the other version is hour, minute and second,

01:51.980 --> 01:56.630
and the other version is hour, minute, second and nanosecond precision.

01:56.630 --> 02:01.580
And the other option is of nano of day of second of day.

02:01.580 --> 02:07.250
Basically, we will we'll pass the nanosecond of the day and will pass the second of the day, which

02:07.250 --> 02:09.710
will give you the appropriate local time.

02:10.460 --> 02:16.280
As a result, we're going to explore these three options now because these are the most common commonly

02:16.280 --> 02:18.410
used methods.

02:18.410 --> 02:25.700
In order to create a local time instance, I'm going to pass the value as 2333.

02:27.230 --> 02:28.070
Local time.

02:29.090 --> 02:29.630
Local time.

02:29.630 --> 02:30.020
One.

02:31.270 --> 02:33.280
Wanna copy this and put it here.

02:35.100 --> 02:38.400
Let's print the local time one.

02:40.100 --> 02:47.170
But on this program, this is going to give me the time instance which we used here of method.

02:47.350 --> 02:52.210
So here, if we take a look at it, the time it printed is 23 and 33.

02:52.210 --> 02:56.010
It did not print the second and nanosecond precision.

02:56.020 --> 02:58.000
Now let's use the other version.

03:00.900 --> 03:05.610
I'm going to give it a name and I'm going to pass the second.

03:08.470 --> 03:10.600
And let's print this and check the result.

03:13.260 --> 03:15.420
Going to be local time too.

03:15.630 --> 03:17.010
And local time, too.

03:17.250 --> 03:20.220
Let's run this and check what is the result.

03:21.730 --> 03:27.230
If you take a look at it, the result is 23, 33, and the second position is also printed.

03:27.250 --> 03:31.240
If you pass a nanosecond, it is going to give you the nanosecond position too.

03:31.420 --> 03:32.950
I'm going to just put it here.

03:34.520 --> 03:40.430
Local time three since it's a nanosecond, I'm going to give the values.

03:43.660 --> 03:44.620
And then.

03:45.600 --> 03:49.620
Put it here so that it will be clear for the whole and the whole screen.

03:49.620 --> 03:54.870
It will fit the whole screen so that you will be able to view it then.

03:56.060 --> 03:56.870
Right here.

03:57.280 --> 03:59.000
Going to be local time three.

04:00.920 --> 04:02.420
And then I'm going to run this.

04:03.870 --> 04:04.900
Run this example.

04:04.920 --> 04:05.540
There you go.

04:05.550 --> 04:10.410
It gives you the nanosecond value of the time.

04:10.860 --> 04:17.280
Now, these are the different options that we have in order to create the local time instance.

04:17.310 --> 04:26.070
Now let's explore how can we get the hour, minute or second and many other parameters from the time

04:26.070 --> 04:27.450
instance that we created here.

04:27.450 --> 04:33.840
I'm going to use the local time as an example, and then I'm going to get the hour minute and the second

04:33.840 --> 04:34.410
from it.

04:34.590 --> 04:35.880
How do we get it?

04:36.450 --> 04:38.910
I'm going to give a simple code comment here.

04:39.690 --> 04:40.620
I'm going to be.

04:41.710 --> 04:43.390
Getting the values.

04:45.180 --> 04:45.750
From.

04:47.510 --> 04:50.120
Local time instance.

04:51.750 --> 04:54.000
So I'm going to use a local time.

04:54.360 --> 04:58.650
I'm going to press dot and then see what are the methods that it supports.

04:58.650 --> 05:01.530
It has a lot of methods, actually.

05:01.530 --> 05:07.260
Now let's explore some of the methods to get the value from the local time instance.

05:07.380 --> 05:13.620
As soon as I type in the get, it gives me the option of get second get or get long get minute and get

05:13.650 --> 05:14.040
nano.

05:14.820 --> 05:21.210
Let's say I want to I want to see what is the hour that this particular local time instance has.

05:21.480 --> 05:25.770
So in that case we'll use the get method.

05:27.980 --> 05:34.760
And then using this, we'll print the R of this local time instance.

05:35.590 --> 05:37.060
Let's run this and check the result.

05:40.010 --> 05:40.670
Take a look at it.

05:40.670 --> 05:45.290
The r value it gave us for that's what.

05:46.150 --> 05:50.380
That is what is the current local times current machines local time.

05:50.410 --> 05:52.690
Now what we'll do we will see.

05:53.110 --> 05:54.400
What is a minute?

05:54.580 --> 05:55.150
Right.

05:55.150 --> 05:57.670
I'm going to use the get minute field.

05:57.670 --> 05:58.960
This is going to return me.

05:58.990 --> 06:02.200
What is a minute of the local time instance?

06:04.220 --> 06:05.150
Put it here.

06:05.390 --> 06:07.280
Let's run this and check the result.

06:09.520 --> 06:10.480
You run this.

06:11.020 --> 06:15.580
It gave the result as 52, which is the machine's current minute.

06:16.450 --> 06:17.140
No.

06:18.500 --> 06:20.000
There are a lot of other methods, right?

06:20.030 --> 06:26.690
Local time dot as you type in the get it is going to give you the option to get the second and it is

06:26.690 --> 06:28.590
going to give you the option to get the Nano.

06:28.610 --> 06:32.920
Now if you take a look at the get method, it accepts something called temporal field.

06:32.930 --> 06:36.890
If you remember from the previous tutorial, we have seen one of the previous tutorial.

06:36.890 --> 06:42.530
We have seen something called the Chrono Field where you can pass the field and then get the actual

06:42.530 --> 06:44.040
value from that local time.

06:44.060 --> 06:48.380
This is one other option basically, but it is going to give you the same result.

06:48.380 --> 06:49.100
Actually.

06:49.250 --> 06:51.050
Let's go ahead and explore this option to.

06:52.080 --> 06:55.320
And then it's going to be Chrono Field.

06:56.440 --> 06:57.100
Dot.

06:58.060 --> 07:02.020
Let's say you want to clock out of the day, you cannot get a day of the month from a time instance.

07:02.020 --> 07:04.510
It's going to give you that unsupported type exception.

07:04.510 --> 07:11.200
So you should pass only the fields that are actually related to the time instance.

07:11.200 --> 07:13.570
So I'm going to give the clock hour of the day.

07:16.160 --> 07:17.840
Run this and check the result.

07:20.680 --> 07:21.430
But here.

07:26.040 --> 07:29.130
And then I'll copy this and put it inside.

07:30.090 --> 07:30.960
There we go.

07:31.350 --> 07:31.800
Run this.

07:31.800 --> 07:38.520
It is going to give me the clock of the day from the actual local time instance.

07:38.520 --> 07:45.210
And the value is for this result is similar to this result, but it is just another alternative to get

07:45.210 --> 07:48.230
the R from the time instance.

07:48.240 --> 07:52.320
Let's say you want to represent this whole time in seconds.

07:52.350 --> 07:54.330
There is an handy option for that one too.

07:54.780 --> 08:01.710
So the method that you have to call is to two seconds to second of day.

08:01.740 --> 08:06.060
Basically, this is this will represent the current time in seconds.

08:08.060 --> 08:09.400
Go ahead and run this example.

08:09.410 --> 08:17.270
So two seconds is going to give you it's going to represent the time in seconds.

08:20.390 --> 08:21.260
Run this.

08:22.210 --> 08:26.560
And the value is 17,006 85.

08:27.930 --> 08:33.540
Now we have seen the different we have seen different options of getting the values from the local time

08:33.540 --> 08:34.150
instance.

08:34.170 --> 08:39.120
Let's go ahead and check how do we modify the time once it is created?

08:39.120 --> 08:41.400
Right now the time is four 5445.

08:41.400 --> 08:41.910
Right.

08:41.940 --> 08:43.740
How can we modify those times?

08:43.890 --> 08:51.090
There are handy options or handy methods that are available in order to modify the value of the local

08:51.090 --> 08:51.600
time.

08:52.530 --> 08:56.700
Modify values of local time.

08:59.790 --> 09:05.040
So if you remember from the local data instance, we are going to use similar kind of methods.

09:05.040 --> 09:09.690
So I would highly recommend you guys to explore all the methods in this local time instance.

09:09.690 --> 09:14.280
But I'm going to give you I'm going to give you the exposure to a few of the methods at this moment,

09:14.280 --> 09:20.100
but please go ahead and run all the different methods that are available so that it will give you the

09:20.100 --> 09:25.500
clarity of how which method to choose on what kind of use case that you are.

09:26.330 --> 09:28.580
Using in your application.

09:28.760 --> 09:32.960
So it's going to be local time, dot minus.

09:32.960 --> 09:35.150
I'm going to subtract the hours by two.

09:36.080 --> 09:41.370
So in that case I can give like minus hours and then pass the long value.

09:41.390 --> 09:49.010
This is going to subtract the hours by two, and the result that it is going to print is something which

09:49.010 --> 09:50.570
we are going to take a look at it now.

09:52.090 --> 09:53.760
Going to be minus hours.

09:57.900 --> 10:00.300
And I'm going to run this example.

10:01.470 --> 10:05.130
Let's check the result and the time is subtracted.

10:05.130 --> 10:11.670
So if you take a look at the current time, the current time is 456 and we subtracted the hours to 256

10:11.670 --> 10:13.740
and again, local time is immutable.

10:13.740 --> 10:16.830
It doesn't change the actual time of that instance.

10:17.040 --> 10:19.110
Now let's say you want to see.

10:20.850 --> 10:24.900
You want to perform the same minus using another alternative approach.

10:24.930 --> 10:28.560
There is a handy way if we give minus.

10:28.590 --> 10:29.250
There you go.

10:29.620 --> 10:33.840
We're going to use this same approach which we have covered in the local date.

10:33.870 --> 10:36.510
There is a similar option which is available in local time too.

10:36.510 --> 10:40.110
So minus long amount to subtract.

10:40.110 --> 10:41.640
And then the temporal unit.

10:41.850 --> 10:42.470
Right.

10:42.480 --> 10:44.370
Let's select that in here.

10:44.370 --> 10:53.820
I want to subtract the hours by two hours and then the unit something which is called Chrono Unit Dot.

10:54.770 --> 10:57.890
Let me put this below so that it will be visible to the.

10:59.600 --> 11:02.530
Students Pronoun unit Dart ahs.

11:05.270 --> 11:08.600
Okay, I'm going to copy this and put it here.

11:09.470 --> 11:12.710
So we are subtracting the hours by two.

11:15.560 --> 11:16.370
There you go.

11:16.550 --> 11:19.280
Give the value as two 5738.

11:19.430 --> 11:20.720
Again, it's all immutable.

11:20.720 --> 11:25.310
It is not going to change the state of the local time instance now.

11:26.400 --> 11:29.610
The Czechs were one of the wet method.

11:31.780 --> 11:36.280
The white matter is something which we explored in the local date video.

11:36.580 --> 11:43.810
Again, we have the similar kind of methods available in local time with and then I'm going to use the.

11:45.700 --> 11:50.260
Local time instance with local time dot.

11:50.770 --> 11:51.610
We take a look at it.

11:51.610 --> 11:57.120
You can give if you want to make this time to be the midnight time, then you can just give this.

11:57.130 --> 12:01.540
So what this is going to do, this is going to change the time to the midnight.

12:04.960 --> 12:05.470
Night.

12:06.100 --> 12:10.900
I'm going to run this example and this is going to give you the time set.

12:10.900 --> 12:12.520
The time as midnight.

12:14.230 --> 12:16.330
Let's say using the width itself.

12:16.360 --> 12:19.240
You want to change the hour of the day?

12:19.960 --> 12:20.620
How do we do it?

12:20.830 --> 12:24.580
So then in that case, we are going to use the two parameter width option.

12:24.610 --> 12:28.330
Let's type in the width and then check if we type in the width.

12:29.250 --> 12:30.360
So there are.

12:30.810 --> 12:32.720
So we just saw this option.

12:32.730 --> 12:38.130
Now we are going to take a look at this option with which takes in the temporal field, followed by

12:38.130 --> 12:39.030
that value.

12:39.330 --> 12:44.490
So we should always, since we are working with the time instance, we should always pass the field

12:44.490 --> 12:49.920
which is of type time, the Chrono Field dot or of day.

12:49.920 --> 12:51.360
I'm going to use the hour of day.

12:51.720 --> 12:54.660
And if you take a look at it, there are a lot of different options.

12:54.660 --> 13:01.080
I would highly recommend you to go through each and every one of it and use the fields that map to the

13:01.080 --> 13:04.020
local time instance, not the date instance.

13:04.050 --> 13:07.440
If we give date, you're going to get something like unsupported type.

13:07.740 --> 13:13.380
So I'm going to use the clock hour or the clock or the hour of day, right?

13:14.280 --> 13:15.260
Hour of day.

13:15.270 --> 13:18.060
And I'm going to set the value as 22.

13:21.720 --> 13:24.140
Gonna run this example and check the result.

13:24.690 --> 13:25.490
We check the result.

13:25.490 --> 13:28.550
It is going to change a time to 22 hours.

13:28.820 --> 13:35.210
So if you take a look at it, it change a time from 459 to 2259.

13:35.540 --> 13:39.350
Now if you want to add some minutes, how do we do it?

13:39.530 --> 13:40.340
Right?

13:42.980 --> 13:44.030
Now, copy this.

13:44.180 --> 13:46.040
Local time, Dot.

13:47.060 --> 13:47.390
Diamond.

13:47.390 --> 13:50.990
Plus, it gives you the all of the different options plus minutes.

13:50.990 --> 13:53.270
And then I'm going to give the value as to.

13:53.390 --> 13:57.110
I'm adding the minutes by to let's go ahead and check the result.

13:57.110 --> 14:02.090
Otherwise I'm going to add the minutes as 30 so that it will be a big difference so that you can easily

14:02.090 --> 14:04.490
compare with the current time.

14:07.790 --> 14:13.400
So if you take a look at the result, the current time is five and the plus minutes, which change at

14:13.400 --> 14:16.100
minutes from zero 0 to 513.

14:16.760 --> 14:26.360
So this is how you add minutes to the local time so you can add our time, our second nanosecond and

14:26.360 --> 14:27.140
all those things.

14:27.170 --> 14:30.860
Now what I'm going to do, I'm going to use the with our method.

14:32.050 --> 14:34.240
The change are of the time.

14:35.020 --> 14:35.890
How do we do it?

14:38.640 --> 14:44.130
The local time dart with R, so it has those methods.

14:44.130 --> 14:50.460
You can directly parse the value and change the hour, minute, nanosecond and second.

14:50.490 --> 14:56.490
So this is again an alternative, but ultimately it is going to give you the same result with R, I'm

14:56.490 --> 14:59.220
going to change the R to ten.

15:00.690 --> 15:03.510
But let's run this example and check the result.

15:05.380 --> 15:06.520
We take a look at it.

15:06.550 --> 15:09.430
It changes a time from zero 5 to 10.

15:10.220 --> 15:12.390
So there are a lot of additional methods.

15:12.410 --> 15:13.280
What are we covered in?

15:13.280 --> 15:16.640
Local date also is supported in local time.

15:16.640 --> 15:22.580
Basically the equal is after, is before and is leap year and all those things.

15:22.580 --> 15:27.230
But leap year doesn't apply here because that's related to the date kind of functionality.

15:27.440 --> 15:31.460
So this is all about the local time instance.

15:31.460 --> 15:33.590
With this, we came to the end of this tutorial.

15:33.620 --> 15:34.790
Thank you for watching.
