filmov
tv
JAVA Tutorial | Easiest Way To Get List Of Dates Between Two Dates In Any Format | SimpleDateFormat
Показать описание
Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
------------------------------------------------
Code Link:-
Subscribe my Channel:-
Facebook Page:-
Twitter Account:-
Blog :-
------------------------------------------------
Hey guys.
In this video, I shall show you the easiest way to get list of dates between two dates in JAVA.
Here I am using netbeans IDE and the date format as year-month and date.
I shall be converting string to date by using date and SimpleDateFormat classes.
With netbeans, you will be assisted to import required packages and handle exceptions.
However, I shall manually handle exception by throwing it in main function line.
Main strategy is to convert date into milliseconds.
Now using LONG as data type is important because the milliseconds are large numbers.
First thing I shall do is to verify if from-date is lesser than to-date by applying if statement.
Now, I shall use for loop, a variable start with from-date and stop at to-date.
In for loop, I shall add 1 day in milliseconds.
One day is 86400 second.
However, 1 second equals to 1000 milliseconds, so add more three zeros.
Let check the output.
Now, the only thing left is to convert milliseconds to date.
For that, SimpleDateFormat variable is required.
Use format function with 1 argument of milliseconds.
The JAVA code handles even a leap as you can see, 29 days in February. 2020 which is the worst year.
The code link is given in the description.
Don’t forget to like, share and subscribe.
Thanks for watching.
------------------------------------------------
Code Link:-
Subscribe my Channel:-
Facebook Page:-
Twitter Account:-
Blog :-
------------------------------------------------
Hey guys.
In this video, I shall show you the easiest way to get list of dates between two dates in JAVA.
Here I am using netbeans IDE and the date format as year-month and date.
I shall be converting string to date by using date and SimpleDateFormat classes.
With netbeans, you will be assisted to import required packages and handle exceptions.
However, I shall manually handle exception by throwing it in main function line.
Main strategy is to convert date into milliseconds.
Now using LONG as data type is important because the milliseconds are large numbers.
First thing I shall do is to verify if from-date is lesser than to-date by applying if statement.
Now, I shall use for loop, a variable start with from-date and stop at to-date.
In for loop, I shall add 1 day in milliseconds.
One day is 86400 second.
However, 1 second equals to 1000 milliseconds, so add more three zeros.
Let check the output.
Now, the only thing left is to convert milliseconds to date.
For that, SimpleDateFormat variable is required.
Use format function with 1 argument of milliseconds.
The JAVA code handles even a leap as you can see, 29 days in February. 2020 which is the worst year.
The code link is given in the description.
Don’t forget to like, share and subscribe.
Thanks for watching.
Комментарии