Hi everyone.
Welcome back to this tutorial.
In this tutorial, we will explore the options of modifying the local date that we created and explore
some of the additional methods that local date supports.
Let's start with modifying the local date instance.
I'll give a quick comment here.
Modifying local date.
No.
We have the current date as let's run this example and check what is the current date.
The current date is 16.
I want to increment the date by two days.
How do I do it?
The local date instance supports a lot of handy methods that can that we can use in order to achieve
our goal.
So as soon as I type in plus it gives me all these options you can do plus days, plus years plus weeks
plus months.
I'm going to explore a couple of options here.
I would highly recommend you guys to explore all the options.
Our use cases, we want to increment the days by two, right?
So in that case we can do plus days and then you have to pass the integer.
So if you take a look at the input to this method, it is just the long it was not integer, it is long.
You just have to give how many days you want to increment.
So here I want to increment the days by two.
So that's the reason why I'm passing the days as two.
Let's check this result.
So the current date is 16 after we run this example.
Let's take a look at the current date.
Though the current date is going to be the local date instance date is going to be 18.
And one more thing, if you notice, it doesn't change the actual instance that got created initially
because as I mentioned in the presentation, all the local date instances that we create are immutable.
So if we go and take a look at the prejudice method, basically this is going to return a new local
date instance using the local date dot off of Epoch Day.
Basically this doesn't disturb the local date instance that we created at all.
So this is one of the important thing to keep in your mind.
This helps us build the programs in functional approach and want to increase the month.
How can we do it?
There is a handy method called.
Last months and I'm going to increase the month by two months.
That's the reason why I'm passing the value as two.
And if I run it, you'll be able to see the value as nine here in the place of seven.
There you go.
It printed the value as nine.
And if you take a look at the date, date is again 16 because as I mentioned, every time it is going
to create a new date instance, that's the reason why this local date is still pointing to the 16th,
which is a current date.
I want to decrease the date by two days.
How do I do it?
So there is a handy method called.
Minus.
In minors.
If you want to decrease the dates by two, I'll pass two.
And this is going to decrease the date and it is going to print the date as 14.
There you go.
It printed the date is 14 and the current date is 16.
Now, these are the handy methods.
You can modify the date, right?
There are some more options, like with.
Let's explore that as part of this.
Now the local date.
That we type in width.
Width has two different.
Not two.
Three different variations.
Let's say you want to change a year.
You can change it by passing the width year.
I'm going to change the year as 2019.
Let's go ahead and check the result.
Again, this is going to be immutable.
It does not going to change the current state of local date.
It is going to give you a new date and it doesn't disturb the current local date instance.
If you take a look at it, the year got changed to 2019 from 2018.
Now let's take a look at some more options with.
The word has many different versions now.
We are going to explore the one with the temporal field.
The temporal field is something.
Similar to the Chrono Field we are going to pass.
Let's say you want to change the year.
There are a lot of different options.
If you take a look at it, it supports a lot of different options.
But here, in order to keep the example simple, what I'm going to do, I'm going to do the year.
You want to change the hour of the day?
You can pass the hour of the day.
You want to change the month of the year.
You can pass by calling this enum constant.
So here I'm going to change the year, right?
I want to change the year to 2020.
Soviet Chrono Field.
Donna Field I'm going to put it down so that it will be visible throughout the presentation.
Now, if I run this example, the date is going to be 2020.
As you see here, the date got changed to 2020.
And let's explore the other option, which is the temporal adjusters.
Don't check that.
I'll copy the same thing.
So we are going to explore the width method only.
The width method has.
Some reason it is acting weird.
Okay, now we are going to use the temporal adjusters.
Temporal adjusters are something which is part of the Java runtime package, and it supports a lot of
handy functionalities for you.
Let's say you want to get the first day of the next month.
You want to set that date to be the first day of next month.
You can call that one and it has a lot of additional methods.
I would highly recommend you guys to go through it and post any kind of questions in the Q&A.
I'll be able to respond to you as fast as I can.
So I want the first day of next month to be set against this local date instance in that case.
What to name this one.
As with temporal adjusters, we run this example.
It is going to give me the date as the first month, meaning first day of the next month.
The next month is zero eight and the first day is zero one.
If you compare this with the earlier versions of date and Time libraries that are part of Java, the
new additions are really handy and intuitive.
This means the local date to be the first choice to use when you are building some functionalities that
are related to date.
Let's go ahead and explore some more additional features that are part of the local date in the upcoming
tutorials.
With this, we came to the end of this tutorial.
Thank you for watching.