WEBVTT

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

00:00.860 --> 00:02.260
Welcome back to this tutorial.

00:02.270 --> 00:08.420
In this tutorial, we will code and explore the new DateTime libraries that got introduced as part of

00:08.420 --> 00:09.440
Java eight.

00:10.300 --> 00:18.070
The new date time libraries are local date, local time and local date and time, and these are available

00:18.070 --> 00:20.710
in the Java dot time package.

00:22.740 --> 00:29.070
These new classes are created with inspiration from the Joda Time External library.

00:30.430 --> 00:35.560
All these classes are immutable, which promotes the functional programming.

00:37.060 --> 00:43.390
There are many more supporting classes that are part of the Java runtime package, such as Instant duration

00:43.540 --> 00:45.440
period and et-cetera.

00:45.460 --> 00:49.720
We will be coding each and every one of it in the following tutorials.

00:52.640 --> 00:58.400
Prior to these time libraries, the most common date and time libraries that were part of Java are date

00:58.400 --> 00:59.360
and calendar.

00:59.390 --> 01:05.390
Both of these classes have many limitations and it is always confusing to choose between the two.

01:05.420 --> 01:08.660
I'm not going to focus on the limitations of these classes.

01:08.670 --> 01:15.820
Then came the external time Libraries like Joda time solved many problems which date and calendar had,

01:15.830 --> 01:20.450
but the Java date and calendar libraries were not great.

01:20.480 --> 01:25.760
That inspired the Java creators to come up with these excellent additions.

01:26.900 --> 01:33.410
Local data is used to represent the date and local time is used to represent the time and local date

01:33.460 --> 01:33.830
time.

01:33.830 --> 01:37.040
Class is used to represent the date and time.

01:37.040 --> 01:43.190
Let's go ahead and explore some of the code samples in this tutorial and we will explore more advanced

01:43.280 --> 01:46.760
date and calendar functionalities in the future tutorials.

01:47.660 --> 01:48.780
Want to go to the village.

01:48.850 --> 01:49.690
There you go.

01:49.720 --> 01:55.990
What I'm going to do the first thing, I'm going to create a package called dates.

01:56.900 --> 02:04.850
And then I'm going to create a class called New Date Time example.

02:07.380 --> 02:10.890
Let's make this class executable by adding public static void main method.

02:12.550 --> 02:14.140
Put this in presentation mode.

02:15.460 --> 02:19.240
So the first thing is I'm going to create the local date instance.

02:19.690 --> 02:20.770
And then.

02:21.980 --> 02:29.420
The local time instance and then the local date time instance.

02:29.750 --> 02:31.920
How do we create the local date instance?

02:31.940 --> 02:36.830
There is a handy factory method that is part of the local date class itself.

02:36.860 --> 02:37.430
We give the.

02:37.460 --> 02:40.220
Now there are three different overloaded versions.

02:40.220 --> 02:43.430
We'll be covering all those different versions in the future tutorials.

02:43.430 --> 02:44.870
But for now, let's.

02:46.200 --> 02:50.070
Although no method which doesn't take any input parameter.

02:51.090 --> 02:54.900
And then this is going to return you a local date instance.

02:57.490 --> 02:58.990
I'm gonna print it here.

02:59.940 --> 03:04.320
But this one is going to give you the current machines, local data.

03:04.470 --> 03:05.520
That's what it's going to do.

03:09.280 --> 03:11.110
Copy this and put it here.

03:14.770 --> 03:19.270
If you run this program, it is going to print this machine's local data.

03:19.600 --> 03:20.320
There you go.

03:20.560 --> 03:22.470
Go to the local date.now method.

03:22.840 --> 03:28.420
So it gives the system's default zone and then it is going to give you the current.

03:29.420 --> 03:29.750
It.

03:31.210 --> 03:32.620
Of this machine in here.

03:32.620 --> 03:38.260
If you take a look at the local date, local date implements a lot of other features like temporal.

03:38.290 --> 03:42.040
Temporal adjusters, Chrono, local date and serializable.

03:42.100 --> 03:47.010
We'll be focusing on all these different things in the future tutorials, but for now you need to know.

03:47.030 --> 03:49.540
Local date is a type of temporal.

03:51.580 --> 03:53.120
And then it printed the date here.

03:53.140 --> 03:55.540
Now we will explore the local time.

03:55.690 --> 03:57.580
The local time is again.

03:59.630 --> 04:05.320
Is going to it's going to be similar like the local date, but it is going to give you the time of this

04:05.320 --> 04:06.100
machine.

04:06.100 --> 04:10.990
So there is a handy method local time dot Now I'm going to call this method.

04:10.990 --> 04:15.520
This one is going to give you the current time of this machine.

04:16.640 --> 04:19.280
Then I'm going to put it here and put it here.

04:19.280 --> 04:20.810
Let's run this and check.

04:21.930 --> 04:22.710
You run this.

04:22.720 --> 04:23.280
There you go.

04:23.290 --> 04:26.080
It gave you the current time of this machine.

04:26.080 --> 04:31.360
Again, if you go to this now method, it is going to give you the system default zone.

04:31.720 --> 04:37.840
There are many different versions of overloading the zone to a totally different zone and getting that

04:37.840 --> 04:39.430
zone time actually.

04:39.440 --> 04:42.280
So we'll be covering all those different scenarios in the future.

04:42.280 --> 04:43.150
Tutorials.

04:43.240 --> 04:44.800
For now, you need to know this.

04:44.920 --> 04:48.250
The local date again is a type of temporal.

04:48.250 --> 04:54.100
It implements all these four interfaces and if you take a look at it, it implements a comparable local

04:54.100 --> 04:54.580
time.

04:56.640 --> 04:58.230
Next comes the local date.

04:58.260 --> 04:58.560
Time.

04:58.560 --> 04:59.250
Local date.

04:59.280 --> 05:01.530
Time is a combination of both, actually.

05:01.560 --> 05:04.080
So how can we get how can we do it?

05:04.200 --> 05:05.820
How can we create an instance of it?

05:05.970 --> 05:07.200
I'm going to give it a name.

05:07.200 --> 05:10.380
It's going to be local date time dot now.

05:12.130 --> 05:15.460
And then I'm going to copy this line and then put it here.

05:16.370 --> 05:19.580
Going to be local date time and local date time.

05:19.700 --> 05:20.510
We run this.

05:20.540 --> 05:24.890
It's going to give you the machine's date and time together.

05:25.070 --> 05:25.440
There you go.

05:25.460 --> 05:27.920
It gave you the time and date together.

05:29.140 --> 05:32.680
So this is all about the local date and time before we wind up.

05:32.680 --> 05:38.140
This one would like to go inside this class and explain about what are the different interfaces that

05:38.140 --> 05:45.370
it implements is again implementing the temporal temporal adjust adjuster and chrono local date and

05:45.370 --> 05:46.660
time and serializable.

05:47.140 --> 05:51.100
I'll be focusing on all these things in the future tutorials, but for now you need to know this.

05:53.080 --> 05:55.540
So this is all about the local date.

05:55.570 --> 05:59.050
Local time and local date time.

05:59.320 --> 06:02.380
Classes that got introduced as part of the Java eight.

06:02.890 --> 06:06.220
Let's focus on more advanced use cases in the future tutorials.

06:06.250 --> 06:08.230
With this we came to the end of this tutorial.

06:08.260 --> 06:09.430
Thank you for watching.
