Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6842513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:06:34+00:00 2026-05-27T00:06:34+00:00

I attempted to generate the date range between date x and date y but

  • 0

I attempted to generate the date range between date x and date y but failed. I have the same method in c# so I tried to modify it as much as I can but failed to get result. Any idea what I could fix?

private ArrayList<Date> GetDateRange(Date start, Date end) {
    if(start.before(end)) {
        return null;
    }

    int MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
    ArrayList<Date> listTemp = new ArrayList<Date>();
    Date tmpDate = start;

    do {
        listTemp.add(tmpDate);
        tmpDate = tmpDate.getTime() + MILLIS_IN_DAY;
    } while (tmpDate.before(end) || tmpDate.equals(end));

    return listTemp;
}

To be honest I was trying to get all the dates starting from january 1st till the end of year 2012 that is december 31st. If any better way available, please let me know.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:06:35+00:00Added an answer on May 27, 2026 at 12:06 am

    Joda-Time

    Calendar and Date APIs in java are really weird… I strongly suggest to consider jodatime, which is the de-facto library to handle dates.
    It is really powerful, as you can see from the quickstart: http://joda-time.sourceforge.net/quickstart.html.

    This code solves the problem by using Joda-Time:

    import java.util.ArrayList;
    import java.util.List;
    
    import org.joda.time.DateTime;
    
    
    public class DateQuestion {
    
        public static List<DateTime> getDateRange(DateTime start, DateTime end) {
    
            List<DateTime> ret = new ArrayList<DateTime>();
            DateTime tmp = start;
            while(tmp.isBefore(end) || tmp.equals(end)) {
                ret.add(tmp);
                tmp = tmp.plusDays(1);
            }
            return ret;
        }
    
        public static void main(String[] args) {
    
            DateTime start = DateTime.parse("2012-1-1");
            System.out.println("Start: " + start);
    
            DateTime end = DateTime.parse("2012-12-31");
            System.out.println("End: " + end);
    
            List<DateTime> between = getDateRange(start, end);
            for (DateTime d : between) {
                System.out.println(" " + d);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have attempted to generate a triangular probability distribution in Matlab, but was not
I'm new to std::generate and have attempted to structure a program which uses it
Summary How can you make ant repeatedly generate byte-identical jar files from the same
I attempted to re-size two buttons in MSIE, so they would be extra-large but
My attempted solution was: $date = Nov 30 2009 03:00:00:000PM; echo date(F Y, strtotime($date));
I have attempted to use this CSS to set the width of my form
I want to generate xml file from Struts action object. So that I have
The following code will generate a link to the page I want to get
I have a project with requirements to generate a single executable file with no
I have the following code : $id = $_GET['id']; // get the recod from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.