Hi everyone.
Welcome back to this tutorial.
In this tutorial we will code and explore how to convert a local date and local time to a local date
and time, and how to get a local date and local time from a local date time instance.
Let's go ahead and code this one.
Though the use cases.
Converting.
Local date.
And local time to local date time.
And vice versa.
The first thing is let's create an instance of local date.
Let's give it a name and it's going to be local date.
Off.
I'm going to give the year 2019 zero one and zero one.
So we have the local date instance already.
How can we get a local date time from this?
So we take a look at the local date.
There is a handy method called add time.
If you pass the hour and minute here, I'm going to pass the minute as 23, comma 33.
So what this is going to do, this is going to add these times to the date and then return the local
date and time as a response.
Let's go.
Go ahead and check what is what is this method does actually, we take a look at it.
It returns the local date time as a output.
But if you take a look at it, it converts.
The date that we are passing and then adding the time to it so that it can be able to return a local
date time.
So we if you remember, we have explored a method called local date dot off, which takes a local date
and local time and returns the local date time as a output.
That's what it does behind the scenes.
Let's run this example.
I'm going to remove the semicolon here.
Let's run this example and check the result.
So if you take a look at that time, it has both the date and time as a output.
Now let's explore how to get a local date time from a local time instance.
Local time.
Equal to local time.
Dot of.
I'm going to give the value as 2359.
Okay in here, we are going to add date to it and then get the local date time as a output.
So local time.
But there is a handy method called at date to which we have to pass the date.
What I'm going to do, I'm going to pass the date instance that we created here.
Let's run this and check the result.
It's going to be.
At date.
Okay, let's run this and check the example.
I'll remove this extra semicolon here.
If you take a look at the update, the output is the combination of date and time.
This is these are the different approaches of converting a date to a local date and time, yet time
to a local date and time.
How can we get a local date and local time from the local date and time instance?
So what I'm going to do.
I'm going to copy this code.
So we all know this is going to give us the local date and time as an output.
So I'm going to give it a name from this instance.
I'm going to get the local date and local time as an output.
How do I do it?
So we use this date time three instance.
We take a look at it.
There is a method called to local data.
So this to local date will just give you the date out of the local date and time instance.
I'm going to print it here.
And then I'm going to do the similar thing for the time.
Go ahead and check what is the method it has.
It has a two local time method which will just give you the time out of the local date and time instance.
Okay, let's run this and check the result.
There you go.
It printed the result for the two local date.
It printed the date and two local time.
Just printed the time.
So these are the different approaches of getting the local date and time from a local date time instance
and converting a local date and local time to a local date time instance.
With this, we came to the end of this tutorial.
Thank you for watching.