WEBVTT

00:00.710 --> 00:01.310
Hi everyone.

00:01.310 --> 00:02.690
Welcome back to this tutorial.

00:02.690 --> 00:09.950
In this tutorial, we'll go ahead and learn about how to convert a local date time to a zoned date and

00:09.950 --> 00:10.520
time.

00:12.120 --> 00:13.530
In this implementation mode.

00:17.290 --> 00:17.660
You go.

00:17.810 --> 00:19.520
Now we are going to.

00:22.870 --> 00:30.220
Convert from local date time comma instant to don't.

00:31.660 --> 00:31.990
Local.

00:33.490 --> 00:34.510
Date and time.

00:37.040 --> 00:37.370
Okay.

00:37.400 --> 00:40.460
First thing is let's create an instance of local datetime.

00:41.360 --> 00:42.470
Local datetime.

00:44.260 --> 00:45.430
Let's give it a name.

00:46.320 --> 00:50.400
And then it's going to be local date time dot now.

00:52.640 --> 00:54.440
Let's print this and check the result.

00:54.470 --> 00:57.170
I'm going to print this and check the result.

01:05.040 --> 01:05.640
Reprinted printed.

01:05.640 --> 01:11.220
It is going to give me the This machine's local date and time.

01:11.340 --> 01:12.000
Take a look at it.

01:12.000 --> 01:18.900
That is output and it doesn't have any offset or zone related information as part of it.

01:19.230 --> 01:24.160
How can we convert this local date and time to a zone date and time?

01:24.180 --> 01:25.470
It's very easy.

01:26.420 --> 01:28.600
Now let's use the instance that we created.

01:28.610 --> 01:31.340
Local date time three dot.

01:31.670 --> 01:35.230
There is a handy method called add zone A zone.

01:35.240 --> 01:37.490
I'm going to pick one of the zone from the above.

01:38.560 --> 01:40.030
Going to pick a Chicago.

01:44.830 --> 01:47.230
And then pass it here.

01:48.760 --> 01:49.860
You take a look at it.

01:50.550 --> 01:56.250
The zone method is going to take that zone and then assign that zone to that local date and time.

01:56.250 --> 01:57.120
And what is that?

01:57.120 --> 01:57.940
It is returning.

01:57.960 --> 02:01.470
It is returning us something called a zone date and time.

02:01.470 --> 02:04.500
That's what we covered in the previous tutorial.

02:07.260 --> 02:10.740
Now let's assign that value zone a date and time.

02:11.040 --> 02:14.170
Give it a name and print.

02:14.290 --> 02:16.200
Let's print this one and then check the result.

02:21.710 --> 02:22.300
This.

02:23.780 --> 02:28.030
This is a local daytime instance, and this is a zone daytime instance.

02:28.050 --> 02:29.640
Let's run this and check the result.

02:31.910 --> 02:32.750
Check the result.

02:33.080 --> 02:40.160
It added the offset and the timezone to that particular local time instance.

02:40.160 --> 02:41.660
That's what it does.

02:41.690 --> 02:43.640
Now what I'm going to do.

02:44.620 --> 02:47.170
I'm going to use the instant instance.

02:48.210 --> 02:50.040
Instant dot.

02:50.220 --> 02:55.770
Now, this one also have a handy method called add zone.

02:56.870 --> 02:58.940
Then I'm going to pass a different zone here.

02:58.940 --> 03:02.240
I'm going to pass the zone as Detroit.

03:03.880 --> 03:05.670
Detroit is in the Eastern Time zone.

03:05.680 --> 03:11.890
Basically, it is one hour ahead of the America and Chicago time zone.

03:12.250 --> 03:19.150
Now, instant dot now is going to give me this machine's local date and time and then.

03:19.510 --> 03:23.080
But this will represent the date and time as a huge number.

03:23.440 --> 03:30.520
Doesn't give you any time date information in human readable format.

03:30.550 --> 03:33.310
We saw those examples in one of the prior tutorials.

03:33.610 --> 03:39.340
Now if you go to the Add zone method, this is also going to return the zone date time instance.

03:40.910 --> 03:42.520
I'm going to create an instance.

03:45.530 --> 03:46.670
I copy this code.

03:47.660 --> 03:49.190
From here and then put it here.

03:50.190 --> 03:54.030
Bambi zoned daytime two and zoned daytime two.

03:54.330 --> 03:56.040
Let's run this and check the result.

03:58.760 --> 03:59.890
We check the result.

04:00.130 --> 04:09.160
It gave the American Detroit the GMT time is actually meaning the offset time is -four hours from the

04:09.160 --> 04:10.060
GMT time.

04:10.060 --> 04:18.070
And if you take a look at the time, the time is zero six, which is one hour ahead of the time.

04:18.520 --> 04:25.390
Now, what I'm going to do, I'm going to just add the offset to it, not both offset and time zone.

04:25.390 --> 04:27.700
I just want to add offset.

04:27.730 --> 04:31.960
So in that case, there is a handy class called offset date and time.

04:31.990 --> 04:36.310
So what I'm going to do, I'm going to use the same instance here, local date time.

04:36.310 --> 04:39.670
And if you take a look at it, there is something called ad offset.

04:40.030 --> 04:47.530
So I'm going to use the zone offset class zone offset class has something called off hours and then

04:47.530 --> 04:53.770
I'm going to pass minus six, which is equivalent to the Eastern Time zone or not the Eastern Time zone,

04:53.770 --> 04:55.000
I believe that is MST.

04:56.590 --> 04:57.340
We take a look at it.

04:57.340 --> 05:01.750
This is MST, So this is one example which we coded in the prior tutorial.

05:01.750 --> 05:06.760
And if you go and take a look at this method, this returns something called offset date and time.

05:09.540 --> 05:11.990
So I'm going to give offset date and time.

05:12.140 --> 05:15.590
Let's print this value and compare this with a zoned date and time.

05:16.550 --> 05:22.710
We'll be able to understand the difference between the offset date and time and the zone date and time.

05:22.730 --> 05:25.730
After we check the result in the console.

05:29.380 --> 05:33.610
If you take a look at it, the offset date and time just adds the offset.

05:33.640 --> 05:36.040
It doesn't add anything related to the.

05:36.900 --> 05:37.200
Don.

05:38.280 --> 05:42.630
So that's the difference between the offset date and time and zoned date and time.

05:43.180 --> 05:49.530
So this is all about the different zone related classes that are released as part of the Java eight.

05:50.220 --> 05:52.230
With this, we came to the end of this tutorial.

05:52.260 --> 05:53.400
Thank you for watching.
