Hi everyone.
Welcome back to this tutorial.
In this tutorial, we will code and explore the new DateTime libraries that got introduced as part of
Java eight.
The new date time libraries are local date, local time and local date and time, and these are available
in the Java dot time package.
These new classes are created with inspiration from the Joda Time External library.
All these classes are immutable, which promotes the functional programming.
There are many more supporting classes that are part of the Java runtime package, such as Instant duration
period and et-cetera.
We will be coding each and every one of it in the following tutorials.
Prior to these time libraries, the most common date and time libraries that were part of Java are date
and calendar.
Both of these classes have many limitations and it is always confusing to choose between the two.
I'm not going to focus on the limitations of these classes.
Then came the external time Libraries like Joda time solved many problems which date and calendar had,
but the Java date and calendar libraries were not great.
That inspired the Java creators to come up with these excellent additions.
Local data is used to represent the date and local time is used to represent the time and local date
time.
Class is used to represent the date and time.
Let's go ahead and explore some of the code samples in this tutorial and we will explore more advanced
date and calendar functionalities in the future tutorials.
Want to go to the village.
There you go.
What I'm going to do the first thing, I'm going to create a package called dates.
And then I'm going to create a class called New Date Time example.
Let's make this class executable by adding public static void main method.
Put this in presentation mode.
So the first thing is I'm going to create the local date instance.
And then.
The local time instance and then the local date time instance.
How do we create the local date instance?
There is a handy factory method that is part of the local date class itself.
We give the.
Now there are three different overloaded versions.
We'll be covering all those different versions in the future tutorials.
But for now, let's.
Although no method which doesn't take any input parameter.
And then this is going to return you a local date instance.
I'm gonna print it here.
But this one is going to give you the current machines, local data.
That's what it's going to do.
Copy this and put it here.
If you run this program, it is going to print this machine's local data.
There you go.
Go to the local date.now method.
So it gives the system's default zone and then it is going to give you the current.
It.
Of this machine in here.
If you take a look at the local date, local date implements a lot of other features like temporal.
Temporal adjusters, Chrono, local date and serializable.
We'll be focusing on all these different things in the future tutorials, but for now you need to know.
Local date is a type of temporal.
And then it printed the date here.
Now we will explore the local time.
The local time is again.
Is going to it's going to be similar like the local date, but it is going to give you the time of this
machine.
So there is a handy method local time dot Now I'm going to call this method.
This one is going to give you the current time of this machine.
Then I'm going to put it here and put it here.
Let's run this and check.
You run this.
There you go.
It gave you the current time of this machine.
Again, if you go to this now method, it is going to give you the system default zone.
There are many different versions of overloading the zone to a totally different zone and getting that
zone time actually.
So we'll be covering all those different scenarios in the future.
Tutorials.
For now, you need to know this.
The local date again is a type of temporal.
It implements all these four interfaces and if you take a look at it, it implements a comparable local
time.
Next comes the local date.
Time.
Local date.
Time is a combination of both, actually.
So how can we get how can we do it?
How can we create an instance of it?
I'm going to give it a name.
It's going to be local date time dot now.
And then I'm going to copy this line and then put it here.
Going to be local date time and local date time.
We run this.
It's going to give you the machine's date and time together.
There you go.
It gave you the time and date together.
So this is all about the local date and time before we wind up.
This one would like to go inside this class and explain about what are the different interfaces that
it implements is again implementing the temporal temporal adjust adjuster and chrono local date and
time and serializable.
I'll be focusing on all these things in the future tutorials, but for now you need to know this.
So this is all about the local date.
Local time and local date time.
Classes that got introduced as part of the Java eight.
Let's focus on more advanced use cases in the future tutorials.
With this we came to the end of this tutorial.
Thank you for watching.