WEBVTT

00:00.410 --> 00:00.920
Hi everyone.

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

00:02.240 --> 00:09.530
In this tutorial we will code and explore how to format and parse a local time using DateTime formatter.

00:09.650 --> 00:12.260
We're going to create a class called.

00:13.440 --> 00:14.210
Murmuring.

00:14.520 --> 00:16.950
Local time example.

00:17.650 --> 00:20.010
Want to make this class executable by adding.

00:20.950 --> 00:22.630
Public static void main method.

00:23.620 --> 00:25.360
Let me put the presentation mode.

00:26.080 --> 00:26.620
Here we go.

00:26.650 --> 00:28.660
I'm going to create two methods.

00:29.720 --> 00:30.590
To be public.

00:31.900 --> 00:32.500
Derek.

00:33.540 --> 00:34.050
White.

00:35.300 --> 00:35.990
Pass time.

00:36.320 --> 00:40.280
And then the another method is going to be public.

00:41.390 --> 00:44.630
Eric Boyd, former time.

00:44.660 --> 00:48.560
So we're going to follow the same approach that we used for the local date.

00:48.650 --> 00:54.320
But in here we're going to talk about format local time and pass local time.

00:54.350 --> 00:56.540
The first thing is I'm going to use.

00:57.780 --> 01:02.730
Ring because pass is something which is going to convert a string to a local time, right?

01:02.730 --> 01:04.590
So I'm going to give it a time.

01:05.070 --> 01:07.350
Going to be 1300.

01:09.070 --> 01:09.580
There you go.

01:09.730 --> 01:14.770
Now what I'm going to do, I'm going to use the local time dot parse method.

01:16.080 --> 01:21.060
So let's use the one parameter version and then we'll cover the parameter version in a bit.

01:21.480 --> 01:23.670
So in here, I'm going to pass the time.

01:24.670 --> 01:31.090
You go to this method, it is going to use the local time in the scenes for you.

01:31.150 --> 01:38.590
You take a look at it, it is expecting a R and two digits followed by the colon and then in it in two

01:38.590 --> 01:40.690
digits, the optional start rate.

01:40.690 --> 01:44.680
So if there is a second, it is going to consider that If there is no second, then it is not even going

01:44.680 --> 01:46.090
to consider that.

01:46.690 --> 01:49.900
So in here, I'm going to give you a local time.

01:50.260 --> 01:51.340
I'm going to give it a name.

01:52.540 --> 01:54.520
So let's print this and check the result.

01:59.540 --> 02:00.060
There you go.

02:00.140 --> 02:02.900
Now I'm going to call both of these methods.

02:04.030 --> 02:05.890
Pastime then.

02:07.580 --> 02:08.010
Format.

02:08.060 --> 02:08.540
Time.

02:09.710 --> 02:14.060
So now what we will do is we will run this example and check the result.

02:16.330 --> 02:16.780
There you go.

02:16.810 --> 02:20.170
It successfully passed the time.

02:20.350 --> 02:23.200
Basically, it converted the string to a local time.

02:23.230 --> 02:25.910
Now let's explore the two parameter version.

02:25.940 --> 02:26.230
Right.

02:26.230 --> 02:28.870
Local time dot parse.

02:28.870 --> 02:35.350
I'm going to pass the same time followed by that I'm going to use the datetime formatter and we are

02:35.350 --> 02:37.900
going to use datetime formatter.

02:38.200 --> 02:40.240
We're going to use the ISO.

02:42.230 --> 02:43.310
Not coming up at.

02:44.870 --> 02:50.060
It informative that it's not be this I used to local time.

02:50.540 --> 02:51.320
Right.

02:51.320 --> 02:55.910
So this is a format which is going to support the R colon the minute.

02:56.550 --> 02:57.000
Format.

02:57.690 --> 02:59.550
I'm going to give it a local time.

03:01.030 --> 03:03.190
And it's gonna give it a name.

03:05.090 --> 03:07.160
And let's print this and check the result.

03:07.470 --> 03:13.700
So if I copy this and put it here, this is going to print the time as expected.

03:16.650 --> 03:18.970
At the time as expected.

03:18.990 --> 03:22.440
Now the next step is the custom defined format.

03:23.610 --> 03:25.290
No comment here.

03:26.200 --> 03:27.970
Custom defined format.

03:28.240 --> 03:32.410
So in here, what is that going to happen is that we're going to have a time.

03:34.040 --> 03:34.520
Ring.

03:35.440 --> 03:41.980
Time one is going to be 13 DA and then 100.

03:43.670 --> 03:44.060
Right.

03:44.060 --> 03:50.310
So this is a custom custom format, which is there is no predefined time in this format and the date

03:50.310 --> 03:51.310
time format class.

03:51.320 --> 04:00.050
Now we are going to create a formatter, the time formatter equal to date in formatter dot of pattern.

04:00.080 --> 04:06.130
The pattern we provide which I want the result in 24 hour format.

04:06.140 --> 04:08.240
That's the reason why I'm using the capital H.

04:08.270 --> 04:11.480
We want the date in a color format.

04:11.480 --> 04:18.500
Then you can use one h and then followed by that it's going to be small M because Capital M represents

04:18.500 --> 04:19.280
the month.

04:19.400 --> 04:21.470
That is something which you have to keep in your mind.

04:21.500 --> 04:26.730
So I'm going to use the local time dot parse.

04:27.050 --> 04:32.270
So we're going to pass the time one followed by the date time formatter that we just created.

04:33.050 --> 04:33.590
There you go.

04:33.800 --> 04:36.560
So now it's going to give you the local time.

04:36.560 --> 04:41.090
I'm going to assign that to a variable, then print the result.

04:42.710 --> 04:44.510
No result.

04:46.650 --> 04:47.950
Go run this.

04:48.000 --> 04:51.390
This is going to give me the local time instance as expected.

04:52.880 --> 04:58.340
We want can play with this by changing this one from capital hedge to small edge.

04:58.820 --> 05:00.200
Run this and check the result.

05:01.220 --> 05:03.110
Take a look at it has some issues.

05:03.110 --> 05:04.520
Let's go ahead and take a look at it.

05:04.550 --> 05:10.970
So the church is expecting only the ranges between 1 to 12.

05:11.000 --> 05:17.470
If you give 13, it is not going to have any clue how to put that value in the color format.

05:17.500 --> 05:19.610
So I'm going to put it back to its old value.

05:20.060 --> 05:23.690
We go run the example and make sure working is expected.

05:24.490 --> 05:27.850
But right now, I'm going to create a time.

05:29.280 --> 05:31.260
Spring time to equal to.

05:32.480 --> 05:33.530
1300.

05:35.500 --> 05:37.500
So I'm going to use the same star.

05:39.790 --> 05:41.290
1300 zero two.

05:41.320 --> 05:43.240
We have seconds also in it.

05:43.570 --> 05:47.080
In those kind of use cases, you're going to define a new pattern.

05:48.340 --> 05:54.160
The name going to have to just represents the seconds.

05:55.120 --> 05:57.850
So I'm going to use similar code here.

06:01.030 --> 06:02.530
So in the place of.

06:04.020 --> 06:07.800
Full time to I'm going to use local time three the place of time.

06:07.800 --> 06:13.620
One, I'm going to use time two because time two is the one which represents the second included ring,

06:13.620 --> 06:17.040
and then followed by that we're going to use the data formatter.

06:17.310 --> 06:19.290
Now let's print this one.

06:21.060 --> 06:23.460
Going to print the local time three.

06:24.430 --> 06:25.360
And local time.

06:25.360 --> 06:25.840
Three.

06:26.600 --> 06:28.040
Run this and check the result.

06:30.880 --> 06:34.960
So it gave you the second included date as expected.

06:35.260 --> 06:40.920
So these are the different ways of converting a string to a local time.

06:40.930 --> 06:46.300
Now, let's go ahead and explore how do you convert a local time instance to a string?

06:46.840 --> 06:48.790
So the reverse approach.

06:49.390 --> 06:52.660
The first thing is I want the date to be in this format.

06:52.840 --> 06:57.610
One, the string that is going to be returned from the local time in this format.

06:58.000 --> 07:03.430
So the first step is I want to create a time instance local time dot.

07:03.430 --> 07:07.030
Now it's going to give you the time instance.

07:07.060 --> 07:08.590
I'm going to give it a name.

07:10.130 --> 07:10.640
There you go.

07:10.760 --> 07:12.990
So we have the local time instance ready.

07:13.010 --> 07:18.780
Let's convert this to a string using the format method, which is part of the local time.

07:18.800 --> 07:21.830
So local time dot call.

07:21.830 --> 07:26.150
The format method basically is going to accept.

07:26.660 --> 07:27.890
Take a look at the format method.

07:27.890 --> 07:30.950
This is going to accept a date time format, for instance.

07:31.250 --> 07:32.300
I'm going to pass that.

07:32.840 --> 07:35.630
So this is going to return a string.

07:36.050 --> 07:39.110
Let's assign this result to a string.

07:39.140 --> 07:39.680
String.

07:41.160 --> 07:41.940
Formatted.

07:43.220 --> 07:44.080
Thymus.

07:45.650 --> 07:48.050
Let's print this and check the result.

07:53.050 --> 07:58.450
So just to just to have some difference in the output, I'm going to have this value as pipe.

07:59.260 --> 08:00.580
This value also as pipe.

08:02.030 --> 08:05.900
If you take a look at it here, I have the current machine's time.

08:06.500 --> 08:07.940
So let me print.

08:09.360 --> 08:13.560
The current machine's time so that we'll be able to relate to the converted date.

08:13.680 --> 08:14.880
So here.

08:15.680 --> 08:16.280
We run it.

08:17.540 --> 08:20.810
Going to give you the result, the pipe symbol.

08:20.810 --> 08:28.520
So the current time of the machine is 650, which is in which is a m and then successfully converted

08:28.520 --> 08:31.960
that to a string of the format that we define here.

08:31.970 --> 08:37.550
So this is all about converting a string to a local time and local time to string.

08:38.320 --> 08:38.560
For this.

08:38.560 --> 08:39.910
We came to the end of this tutorial.

08:39.940 --> 08:41.080
Thank you for watching.
