Date generate from start to end date in java

edge

I am trying to generate a list of dates from a given start and end date. I found the solution in stack overflow . But, the code gives the distribution starting from the month of January. I am unable to find why. Please help me out.

starting , ending are String with format 'yyyy-mm-dd'. duration is the Arraylist I am using to store the dates.

List<Date> duration = new ArrayList<Date>();
         List<Date> date_req = new ArrayList<Date>();
            Calendar start = Calendar.getInstance();


        DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
        Date date_st = formatter.parse(starting);
        Date date_en = formatter.parse(ending);

            int init=0;
            start.setTime(date_st);
            Calendar end = Calendar.getInstance();
            end.setTime(date_en);
            end.add(Calendar.DAY_OF_YEAR, 1); //Add 1 day to endDate to make sure endDate is included into the final list
            while (start.before(end)) {
                duration.add(init,start.getTime());
                start.add(Calendar.DAY_OF_YEAR, 1);
                init=init+1;
            }
          System.out.println(duration); 

Thanks.

sadhu

Your format should be DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd")

Using mm for Month is the reason you get your year starting from JAN

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Generate_series in Postgres from start and end date in a table

From Dev

Week numbers from start date to end date Java

From Dev

Generate start and end dates in a date range Oracle

From Dev

TSQL generate months based on start and end date

From Dev

Start and end date from date range

From Dev

Start and end date from date range

From Dev

Java task scheduler run daily from start to end date

From Dev

Pandas date_range starting from the end date to start date

From Dev

Generate start and end dates for each week of a year starting from any date with PHP

From Dev

Start Date and End Date in Bootstrap

From Dev

Start Date and End Date in AngularJS

From Dev

How can I generate a series of date ranges that fall between a start date and end date?

From Java

Get start date & end date from the range of timestamp

From Dev

JQuery datepickers- setting end date from a start date

From Dev

Combine start date and end date from 2 tables into single table

From Dev

Need help to find start date and end date from a group

From Dev

get the end date base from the given start date

From Dev

Create start and end date from single date column

From Dev

calculate start date and end date from given quarter SQL

From Dev

Java 303 / 349 start date before end date validation

From Dev

Aggregate with a start and end of date

From Dev

Date difference between end date to start date

From Dev

Multiple 'start datetime' and 'end datetime'. Generate a new row for each date between start datetime and end datetime

From Dev

How to get start date and end date from the given date column according to task completion in a day (oracle)

From Dev

Start Date and End Date Of current month in MySql?

From Dev

Angularjs start date and end date validations

From Dev

JQuery - end date less than start date

From Dev

Qml Calendar - selecting Start Date and End Date

From Dev

Qml Calendar - selecting Start Date and End Date

Related Related

  1. 1

    Generate_series in Postgres from start and end date in a table

  2. 2

    Week numbers from start date to end date Java

  3. 3

    Generate start and end dates in a date range Oracle

  4. 4

    TSQL generate months based on start and end date

  5. 5

    Start and end date from date range

  6. 6

    Start and end date from date range

  7. 7

    Java task scheduler run daily from start to end date

  8. 8

    Pandas date_range starting from the end date to start date

  9. 9

    Generate start and end dates for each week of a year starting from any date with PHP

  10. 10

    Start Date and End Date in Bootstrap

  11. 11

    Start Date and End Date in AngularJS

  12. 12

    How can I generate a series of date ranges that fall between a start date and end date?

  13. 13

    Get start date & end date from the range of timestamp

  14. 14

    JQuery datepickers- setting end date from a start date

  15. 15

    Combine start date and end date from 2 tables into single table

  16. 16

    Need help to find start date and end date from a group

  17. 17

    get the end date base from the given start date

  18. 18

    Create start and end date from single date column

  19. 19

    calculate start date and end date from given quarter SQL

  20. 20

    Java 303 / 349 start date before end date validation

  21. 21

    Aggregate with a start and end of date

  22. 22

    Date difference between end date to start date

  23. 23

    Multiple 'start datetime' and 'end datetime'. Generate a new row for each date between start datetime and end datetime

  24. 24

    How to get start date and end date from the given date column according to task completion in a day (oracle)

  25. 25

    Start Date and End Date Of current month in MySql?

  26. 26

    Angularjs start date and end date validations

  27. 27

    JQuery - end date less than start date

  28. 28

    Qml Calendar - selecting Start Date and End Date

  29. 29

    Qml Calendar - selecting Start Date and End Date

HotTag

Archive