WEBVTT

00:00.350 --> 00:00.890
Hi everyone.

00:00.890 --> 00:02.240
Welcome back to this tutorial.

00:02.240 --> 00:09.650
In this tutorial we will code and explore the next date and time library, which is the local date time.

00:10.010 --> 00:12.770
For this purpose, I'm going to create a class.

00:13.690 --> 00:19.300
Called local date time example.

00:20.540 --> 00:25.370
Let's make this class executable by adding public static void main method.

00:29.610 --> 00:34.080
Now, how can we create an instance of local date time?

00:34.710 --> 00:39.270
So the way to create is local date time dot now.

00:39.960 --> 00:41.550
So there are three different versions.

00:41.550 --> 00:44.720
For now, we are going to focus only on this version.

00:44.730 --> 00:49.530
The zone and Clock is something which will be covering when we cover the time zones.

00:50.730 --> 00:56.610
Dot Now this is going to give me an instance of local date time.

00:57.270 --> 00:59.130
Let's print this and check the machines.

00:59.130 --> 00:59.880
Current time.

01:01.270 --> 01:02.380
A secret date and time.

01:03.680 --> 01:04.730
I'm gonna turn.

01:04.730 --> 01:09.150
This is going to be local date and time.

01:09.170 --> 01:10.790
Let's run this and check the result.

01:11.800 --> 01:21.970
So the current date and time is 17th of July and the time is 555 and 54 seconds and 994 is a nanosecond

01:22.180 --> 01:22.690
precision.

01:22.690 --> 01:27.700
Let's take a look at what are the different ways of creating a local date time instance.

01:27.880 --> 01:34.240
The local date time instance as a factory method called off using which you can create a local date

01:34.240 --> 01:35.050
time instance.

01:35.050 --> 01:37.810
If you take a look at it, there are many options available here.

01:37.810 --> 01:42.190
What I'm going to do, I'm going to cover a few of these in this tutorial, but I would highly recommend

01:42.190 --> 01:46.290
you guys to go through and explore all the options that are available here.

01:46.300 --> 01:55.210
Now what I'm going to do, I'm going to pass the year and then the month and then the date and hour,

01:55.390 --> 01:58.810
minute, second and nanosecond.

02:00.700 --> 02:01.370
There you go.

02:01.400 --> 02:03.390
I'm going to put it down so that it will be visible.

02:03.560 --> 02:04.850
It'll fit the whole screen.

02:04.870 --> 02:09.100
Now what I'm going to do, I'm going to create a instance out of it.

02:09.430 --> 02:12.260
So this is a instance.

02:12.280 --> 02:22.510
Let's print this and check the result on how the local datetime instance looks like with the values,

02:22.510 --> 02:23.770
whatever that we passed.

02:23.800 --> 02:26.330
Let's run this when we run this.

02:26.350 --> 02:33.940
It gave you the result as as you see, this is the date which we passed here, meaning 2018, zero 321

02:33.940 --> 02:38.100
and T is a separator which splits the date from the time.

02:38.110 --> 02:45.550
And then we gave the time as 23 hours, 33 minutes and 33 seconds, powered by the nanosecond precision.

02:46.450 --> 02:50.020
Now let's explore another option, which is really, really handy.

02:50.050 --> 02:52.270
Local date time of.

02:52.450 --> 02:53.890
Take a look at the first option here.

02:53.890 --> 02:56.350
It takes in a local date and local time.

02:56.860 --> 02:57.850
Let's do this.

02:58.000 --> 02:59.550
I'm going to pass the local.

02:59.560 --> 03:05.260
I'm going to use the local date class and then call the now method, which is going to give me the current

03:05.260 --> 03:11.380
machines local date and followed by that I'm going to pass the local time dot now, which is going to

03:11.380 --> 03:15.790
return me the current machine's local time.

03:17.240 --> 03:19.760
This is going to return me, the local datetime instance.

03:19.760 --> 03:23.150
I'm going to give it a name and have it here.

03:24.260 --> 03:26.420
Let's print this and check the result.

03:26.660 --> 03:29.300
So I'm going to put it here.

03:29.750 --> 03:30.950
I'm going to put it here.

03:30.950 --> 03:34.940
So here we are passing the local date and time instance.

03:35.090 --> 03:42.200
That will give you the local date time together as a response, which is of type local date time and

03:42.200 --> 03:44.450
then give it a given name here.

03:44.480 --> 03:45.720
That's what we are printing here.

03:45.740 --> 03:47.870
Let's go ahead and run this and check the result.

03:51.040 --> 03:52.120
We take a look at it.

03:52.360 --> 04:00.700
The date and time is the current machines, local date and time, which is separated by a T so it combined

04:00.700 --> 04:04.330
and gave the local date time as a output.

04:04.360 --> 04:10.390
Now let's take a look at what are the different ways of getting the values from the local date time

04:10.390 --> 04:10.810
instance.

04:10.810 --> 04:14.020
Let's say I want to get the hour from the local date instance.

04:14.020 --> 04:14.920
How do we do it?

04:16.090 --> 04:24.130
Getting the time and date from local date time instance.

04:25.430 --> 04:28.280
So first thing is I want to get the ah, how do we do it?

04:29.270 --> 04:32.570
I'm going to have this text here.

04:34.320 --> 04:40.350
So I'm going to use this local datetime instance dot if I give the get.

04:40.380 --> 04:41.900
There are many options available.

04:41.910 --> 04:50.430
I have both the R and D methods available because this local date time is a combination of both date

04:50.430 --> 04:51.330
and time.

04:51.330 --> 04:53.100
So I just need the R right.

04:53.280 --> 04:53.970
I run this.

04:53.970 --> 05:01.650
This is going to print the r that is associated with the local date time and the R six, which is 6

05:01.650 --> 05:03.030
a.m. in the morning here.

05:04.310 --> 05:07.220
Now what I'm going to do, I need the minute.

05:09.560 --> 05:10.670
How do we do it?

05:11.060 --> 05:13.480
So there is a handy method called get minute.

05:13.490 --> 05:16.280
I'm going to use that method and print the result.

05:19.870 --> 05:20.330
There you go.

05:20.350 --> 05:22.450
It printed the minute as 615.

05:22.540 --> 05:28.780
We take a look at the current machines time, the machines, current time it is 615.

05:28.780 --> 05:30.850
So and we got the 15 out of it.

05:30.880 --> 05:33.670
Let's say I want the day.

05:35.300 --> 05:35.930
How do we do it?

05:35.960 --> 05:38.960
There is a method called Get day of the Month.

05:39.510 --> 05:44.930
We give this value going to print the day of the month.

05:45.440 --> 05:47.690
The day of the month is 17.

05:48.850 --> 05:54.520
So these are the different options that are available in order to get the values from the local datetime.

05:54.520 --> 05:57.220
And it also supports the width method.

05:57.280 --> 05:58.990
Let's explore a couple of those.

06:00.850 --> 06:02.080
Local date.

06:03.070 --> 06:04.360
So if we do with.

06:05.350 --> 06:07.840
That is the way of modifying.

06:07.960 --> 06:08.740
Let's cover this.

06:08.740 --> 06:13.840
When we actually modify the when we want to modify the local daytime instance, there is a get method

06:13.840 --> 06:15.750
that is the one which I wanted to cover.

06:15.760 --> 06:19.150
So if you do a get, it accepts a temporal field, right?

06:19.330 --> 06:23.650
So in here we can pass Chrono Field dot one the day of the month.

06:24.880 --> 06:25.660
There we go.

06:25.870 --> 06:29.350
And then this is going to give you the day of the month.

06:29.350 --> 06:35.110
But here, if you take a look at it, we are using another approach in order to get a parameter or in

06:35.110 --> 06:38.260
order to get an attribute from the local date time instance.

06:38.260 --> 06:39.760
I'm going to run this example.

06:41.120 --> 06:41.540
There you go.

06:41.570 --> 06:44.900
It gave the value as 17 because that is the day of the month.

06:45.020 --> 06:50.030
Now let's go ahead and check what are the different options of modifying the values.

06:51.010 --> 06:52.270
In local daytime.

06:53.140 --> 06:58.000
Let's give a simple code command in order to differentiate this from the getting getting the values

06:58.000 --> 06:59.260
from the local daytime.

07:00.280 --> 07:04.380
Modifying local daytime.

07:04.990 --> 07:07.170
So let's say I want to add hours to it.

07:07.180 --> 07:09.340
I want to increase the hours by two.

07:09.670 --> 07:10.540
How do we do it?

07:10.570 --> 07:16.180
So I'm going to use the same local daytime dot you can do.

07:16.180 --> 07:21.270
Plus it has both the days and hours methods supported as part of local daytime.

07:21.280 --> 07:24.550
So I'm going to use plus hours and increase the hours by two.

07:25.810 --> 07:26.890
Let's put this.

07:28.590 --> 07:30.210
Was wrong button.

07:30.490 --> 07:33.450
So in here, I'm going to print this in the console.

07:33.930 --> 07:35.190
Let's put this this out.

07:37.950 --> 07:43.210
And then in here, I'm going to use the plus hours to put the plus hours.

07:44.530 --> 07:46.700
And let's run this and check the result.

07:46.720 --> 07:51.760
Right now, the result will give you 8 a.m. as a result.

07:51.790 --> 07:57.620
If you take a look at the time, the time change from 6 to 8, the current time is six.

07:57.650 --> 08:03.430
It changed the time from 6 to 8 because we have added two hours to the current time.

08:03.700 --> 08:06.070
Now I want to subtract the days.

08:06.070 --> 08:07.060
How do we do it?

08:07.090 --> 08:12.220
There is a handy method, which is the minus which we have seen as part of the local date and local

08:12.220 --> 08:14.140
time tutorials.

08:14.140 --> 08:16.900
So I want to minus the days by two.

08:17.500 --> 08:21.360
So this is going to reduce the date by two.

08:21.370 --> 08:23.190
The current date is 17.

08:23.200 --> 08:26.650
This is going to change the date to 15.

08:26.980 --> 08:28.300
Let's run this and check.

08:30.480 --> 08:31.350
We take a look at it.

08:31.350 --> 08:34.470
The date changed from 17 to 15.

08:35.400 --> 08:36.030
There you go.

08:36.060 --> 08:37.740
Let's take a look at the width method.

08:40.100 --> 08:44.630
So what's going to be local date time dot width.

08:45.560 --> 08:47.240
Let's say you want to change the month.

08:47.970 --> 08:49.280
I want to change the month to 12.

08:49.430 --> 08:51.260
So the width method is handy.

08:51.260 --> 08:55.880
In order to modify the dates you can still use.

08:55.880 --> 08:57.530
Like what is a current month?

08:57.530 --> 08:58.700
The current month is seven.

08:58.700 --> 09:02.000
If you want to change that to 12, you will add a plus five.

09:02.240 --> 09:08.630
So with month, with month is going to change the local times month to 12.

09:10.970 --> 09:12.920
Then let's run this and check the result.

09:14.670 --> 09:15.360
Here we go.

09:15.390 --> 09:18.690
It changed a month from 5 to 12.

09:18.720 --> 09:24.400
So these are the different handy options which you can use in order to modify the local date and time.

09:24.420 --> 09:26.060
There are many more options available.

09:26.070 --> 09:31.860
I would highly recommend you guys to go ahead and explore it and raise any kind of question in the Q&amp;A

09:31.860 --> 09:32.280
section.

09:32.280 --> 09:36.120
I would be able to answer you as soon as I can with this.

09:36.150 --> 09:37.810
We came to the end of this tutorial.

09:37.830 --> 09:38.970
Thank you for watching.
