Hi everyone.
Welcome back to this tutorial.
In this tutorial, we'll go ahead and learn about how to convert a local date time to a zoned date and
time.
In this implementation mode.
You go.
Now we are going to.
Convert from local date time comma instant to don't.
Local.
Date and time.
Okay.
First thing is let's create an instance of local datetime.
Local datetime.
Let's give it a name.
And then it's going to be local date time dot now.
Let's print this and check the result.
I'm going to print this and check the result.
Reprinted printed.
It is going to give me the This machine's local date and time.
Take a look at it.
That is output and it doesn't have any offset or zone related information as part of it.
How can we convert this local date and time to a zone date and time?
It's very easy.
Now let's use the instance that we created.
Local date time three dot.
There is a handy method called add zone A zone.
I'm going to pick one of the zone from the above.
Going to pick a Chicago.
And then pass it here.
You take a look at it.
The zone method is going to take that zone and then assign that zone to that local date and time.
And what is that?
It is returning.
It is returning us something called a zone date and time.
That's what we covered in the previous tutorial.
Now let's assign that value zone a date and time.
Give it a name and print.
Let's print this one and then check the result.
This.
This is a local daytime instance, and this is a zone daytime instance.
Let's run this and check the result.
Check the result.
It added the offset and the timezone to that particular local time instance.
That's what it does.
Now what I'm going to do.
I'm going to use the instant instance.
Instant dot.
Now, this one also have a handy method called add zone.
Then I'm going to pass a different zone here.
I'm going to pass the zone as Detroit.
Detroit is in the Eastern Time zone.
Basically, it is one hour ahead of the America and Chicago time zone.
Now, instant dot now is going to give me this machine's local date and time and then.
But this will represent the date and time as a huge number.
Doesn't give you any time date information in human readable format.
We saw those examples in one of the prior tutorials.
Now if you go to the Add zone method, this is also going to return the zone date time instance.
I'm going to create an instance.
I copy this code.
From here and then put it here.
Bambi zoned daytime two and zoned daytime two.
Let's run this and check the result.
We check the result.
It gave the American Detroit the GMT time is actually meaning the offset time is -four hours from the
GMT time.
And if you take a look at the time, the time is zero six, which is one hour ahead of the time.
Now, what I'm going to do, I'm going to just add the offset to it, not both offset and time zone.
I just want to add offset.
So in that case, there is a handy class called offset date and time.
So what I'm going to do, I'm going to use the same instance here, local date time.
And if you take a look at it, there is something called ad offset.
So I'm going to use the zone offset class zone offset class has something called off hours and then
I'm going to pass minus six, which is equivalent to the Eastern Time zone or not the Eastern Time zone,
I believe that is MST.
We take a look at it.
This is MST, So this is one example which we coded in the prior tutorial.
And if you go and take a look at this method, this returns something called offset date and time.
So I'm going to give offset date and time.
Let's print this value and compare this with a zoned date and time.
We'll be able to understand the difference between the offset date and time and the zone date and time.
After we check the result in the console.
If you take a look at it, the offset date and time just adds the offset.
It doesn't add anything related to the.
Don.
So that's the difference between the offset date and time and zoned date and time.
So this is all about the different zone related classes that are released as part of the Java eight.
With this, we came to the end of this tutorial.
Thank you for watching.