Hey, welcome back you guys. Scott Stanlick here. In this lesson, we're gonna take a look at the new Java Date/Time API. We're gonna see a lot of local date, local time zone date time functionality. We will see how to work with periods and durations to determine time spans between these different temporal types. And then lastly, we will look at temporal adjusters which are just crazy cool. You're going to enjoy it. So let's start off by taking a look at why the Java Date/Time API even came about and it's a storied history. The legacy date and time Gregorian calendars and calendars and whatnot, have been around since Java 1.0 and I'm telling you, they are pretty terrible. They're not thread safe, they're mutable which is to say they can change underneath of you if you're not careful. They're very poorly designed in terms of how they were architected. Dates start with 1900, months start at one, days start at zero, and that's probably enough. It was just crazy. And it was also difficult to handle time zones with the old world. So let's turn the page and let's take a look at this new thing. The new Java Date/Time API is completely rewritten from scratch. It's crystal clear, clean, and it works remarkably well. It's immutable, so you won't see us saying knew this, knew that, or the other. Instead, we'll do things like this. We'll say, I'd like to know what the local date is now. Or I would like to know what the local time is now and local date, local time, or the combination here, local date time, which combines both date and time. They know nothing of time zone, and a lot of times you don't really care and don't need to know. If you do need to concern yourself with time zone, there is a zone date time, as you can see. So these are the four types that are basically the bedrock underneath of this. So there are tons of methods, there are tons of types, but once you start to see how this works, it just rolls off of your tongue. It's so effortless to work with. So for instance, now date, which is my local date here, I can say get month. In this case, I'm going to use the zone date time now as Pacific time. So I say now Central zone date time, that's me here. But with the zone, same instant. In other words, I want to know right now what time it is if I were in Pacific time and it should say two hours ahead of Central. I happen to be in Central. And so if we run this method, we run this test, we should see that I'm in Central time. We should see that now as Pacific time is two hours ahead of me. So let's see here, 17:54 is my time, Chicago Central. Yeah, it is, 15:54, two hours ahead of me. So there we go. We see the local date, the local time with millisecond precision. We see the local date time which is the combination of the two and then we see now Central zone date time. So it's the whole enchilada. And the minus five is negative five hours off of Greenwich Mean time. So when I asked what month it is, it told me August. Fabulous. So let's take a look at some other things that we can do once we have established a point in time, a day or a time. We can do things like add hours, minutes, days, years, you name it. It's available for us to do here. In this case, I'm saying, I'd like to know what tomorrow is. So if today was August 5th, 2022, well tomorrow is going to be plus one day, August 6th, 2022. Great, that would make sense. I'm looking at my calendar. But this thing understands if this happened to have been February 28th, what it should be tomorrow if it's a leap year, if it's not a leap year. If it's December 31st and adding one day ends up rolling it into a new year. It's keenly aware of all of those rollovers. So there's a plus today. I said is tomorrow after today, right? And it just reads just like that. Tomorrow is after today. That's true. When I see today is after tomorrow, it says no. Then I say today, get day of week. It says Friday. Get day of month, five, get day of year, 217. So today's the 217th day of the year. It's beautiful. There is support for backward compatibility. Let me spell that correctly. Support for backward compatibility. And it works like this. I told you earlier on that there were some real problems with the old Date/Time. Like for instance, the year started with 1900. So if I wanted to create my birthday using the old system, I'd have to say 1970 minus 1900. And then five is the month, which is zero based, which is June, which is six. And then the day was actually one base, so 15. That should be June 15th, 1970 and I can print it out. Then I can say, I would like to turn that legacy birthday into a local date time. So this is the bridge, if you will to take the old guy and turn it into a new local date time. So let's run this. I should see the old date and then I should see the new date which is effectively the same point on the timeline. So there's the legacy birth date which was Monday, June 15th, CBT 1970, and here's the modern date, which is the local date time, and they're both June 15th, 1970. So they worked perfectly. Awesome. Thank you for watching.