Welcome back and this video, we are going to finalize our calculation and we will finally display the
age in minutes and therefore we're going to use this date object that we created and we will, first
of all, get the date in minutes.
So follow selected date in minutes and that will be the date that time.
So I want to have the time of my date.
Now, you can see that time is in purple and you can press the control key and hover over it and then
press on it.
And it will open up the data Java file, which contains this get method, which is called get time,
which then returns to get time implemented, which then looks at if the date is not normalized or not
null, then it will normalize it and return first time.
What does all of that mean?
Well, it will return it in a certain format.
I will return it in.
Milliseconds, so if you want to get seconds from milliseconds, we divide by one thousand.
If you want to get minutes, then we divide by sixty thousand.
When we do so and we have our overall date, the date we can see that it says unsafe use of nullable
receiver of type date, which means that the date could be null and could be empty.
And if that's the case and we still want to use it, we can force on Reppert, we can say, OK, the
date is going to be a date object and it's going to work.
So please go ahead and accept it.
And we can do so by using the double exclamation mark here.
This is, of course, tricky if the date is, in fact, not correct.
So if the date is in fact empty or parsing the selected date that we selected doesn't work and so forth.
So, for example, if we made an error when entering this value here, we have to be, of course, super
careful.
So this is something that you should only do if you are certain that the values that you have there
are correct.
Otherwise, you can, of course, build a whole try and catch block around it to check if everything
is fine and and only execute it in a safe environment.
But we're going to keep it simple for now.
We could just say, OK, we force unwrap it.
We say, OK, the date is having a value and we want to get the time from it.
And then we want to divide that by 60 thousand in order to not get the milliseconds, but the actual
minutes which have passed from the moment nineteen seventy 1st of January to the moment of our date.
Because if you again, look at the documentation when we use that time, the gate time method is called
and it returns the number of milliseconds since January 1st, nineteen seventy represented by this date
object.
OK, so that's what I was just talking about.
All right.
So this time, as we saw earlier, calls this get time method, which then in turn returns the time
in milliseconds from 1970 to the moment of the state object, which is in my case, the 12th of December
or actually the 11th of December, two thousand nineteen.
So now that we know how much time has passed between the moment that was selected and 1970, we can
also calculate how much time has passed between now the current day and the first of January, two thousand
or nineteen seventy.
OK, so we can go ahead and get the current date.
Vul current date is equal to ASDF topass.
And now we need to formate.
System not.
Current time in millisecond.
So what I did here is I summed it up in one line, so here we did it before, we did it in multiple
lines.
So first we did get it in a certain format and then it was transferred into the right format, which
then was in turn transformed or.
Converted into a date object.
All right, so here we bring it into the right format, then we bring it into the date object type or
into the date type, and we start in current date and now we can go ahead and calculate the current.
That two minutes, which is going to be the current date.
Which if you look at it here, by the way, current date, it says date questionmark, which means that
current date is an optional or a null type.
So current date.
Here we need to double exclamation mark again, but time divided by sixty thousand.
And now we can go ahead and calculate the difference, so.
Voll Differenced.
In minutes, this current dates to minutes minus selected.
Date in minutes and actually let's keep the same naming, I'm going to use that in minutes here, so
like to take ten minutes.
And yeah, that's it.
So now we have the difference in minutes, which means we now have the value that in fact is the H in
minutes so we can use selected data in minutes.
Our TV, our text you, which is this text you here at the bottom.
So let me scroll the way down here.
This one TV selected data in minutes, which is just text you that is bigger with thirty five USPI,
but which currently is empty.
Now we can go ahead and set its text to our difference in minutes.
And of course, this has to be a string, so to string just to make sure that it has the right format.
All right, and now you can go ahead and test this, let's just see.
All right, so let's select to date, let's say.
We select the 10th of December.
And the H in minutes is one thousand four hundred forty, which is one day, so one day is fourteen
hundred and forty minutes.
So let's say I select my birth date here, which is the 31st of May, nineteen eighty eight.
And I can see this is my H.
All right, that's it.
That's our application, as you can see, it works fine.
Now, let's check what happens if I select the wrong date, for example, something in the future,
then we get a negative value.
So we are minus two thousand eight hundred eighty minutes old.
That's something that you can, of course, use for.
Countdown timer or something like that, but our app is really.
Are to calculate the ten minutes, so doing something like that where we have negative values is not
going to cut it.
That's not the right way to do it.
So what we can do is we can store this whole data, picture, dialogue and a variable.
So I'm just going to say Volle DPD, which stands for data picker dialogue, and then instead of showing
it directly here, I'm just going to.
First of all, limit this DVD or set a setting there, so I'm just going to say DVD dot date picker.
And here I can set the megastate.
And it will be date time, minus eight, six, four and five zeros.
This is just the milliseconds of one day.
And in the next step, I will show the DPD.
So our.
Day to pick your dialogue now this test is again.
So let's select a date in the future, and as you can see, I cannot do it so it doesn't even offer.
These states, so it's limited to the past and I cannot use the future, and how is that possible?
Well, it was made possible by setting the next date to the date, the time, which is the current time
minus.
One day, so we can only select yesterday as the latest moment.
All right, so that's our little app, and I took a little longer than I expected, but that's because
I really went deep into depth here and I really explained very many details.
And yeah, you can, of course, always download the application or better said the project.
And there you will find that we have many comments which explain what's going on there and why the code
is as it is.
So you can just download that.
And that will definitely help you to understand what's going on if something is unclear.
There might be some names which are a little different.
Maybe I decided to change the names while I created the recording, but overall it's pretty much the
same code.
I hope to take advantage of this and of course, also of the documentation because it's super helpful
to understand what's going on.
All right.
So I hope you enjoyed this chapter and.
Yeah, see you in the next one.